;**** macros ******* .macro ldi_ram ;@0 variable @1 immediate value ;write an immediate value into RAM ldi ZL, LOW(@0) ldi ZH, HIGH(@0) ldi temp, @1 st Z, temp .endmacro .macro ld_ram ;@0 variable @1 register ;write a register value into RAM ldi ZL, LOW(@0) ldi ZH, HIGH(@0) st Z, @1 .endmacro .macro st_ram ;@0 register @1 variable in RAM ;write from RAM to register ldi ZL, LOW(@1) ldi ZH, HIGH(@1) ld @0, Z .endmacro .macro add_ram ;@0 variable in RAM @1 variable in RAM ; add variables in RAM ldi ZL, LOW(@0) ldi ZH, HIGH(@0) ld temp, Z ldi ZL, LOW(@1) ldi ZH, HIGH(@1) ld temp1, Z add temp, temp1 ldi ZL, LOW(@0) ldi ZH, HIGH(@0) st Z, temp .endmacro .macro addi_ram ;@0 variable in RAM @1 immediate value ldi ZL, LOW(@0) ldi ZH, HIGH(@0) ld temp, Z ldi temp1, @1 add temp, temp1 ldi ZL, LOW(@0) ldi ZH, HIGH(@0) st Z, temp .endmacro .macro sub_ram ;@0 variable in RAM @1 variable in RAM ; add variables in RAM ldi ZL, LOW(@0) ldi ZH, HIGH(@0) ld temp, Z ldi ZL, LOW(@1) ldi ZH, HIGH(@1) ld temp1, Z sub temp, temp1 ldi ZL, LOW(@0) ldi ZH, HIGH(@0) st Z, temp .endmacro .macro tst_ram ;@0 variable in RAM; equivalent to tst ldi ZL, LOW(@0) ldi ZH, HIGH(@0) ld temp, Z tst temp .endmacro ; given a 8-bit number (0-0xff), convert it into a number range from 0-52 ; random MOD 13, quotient is corresponding to suit, and remainder + 1 is ; corresponding to card number ; quotient = 0: diamond 1: club 2: heart 3: spade ; probably can write a macro for the MOD function ; example: simple_mod random, 52, remainder .macro simple_mod lsr @0 ratio: cpi @0, @1 brlt remainder subi @0, @1 rjmp ratio remainder: mov @2, @0 endm: .endmacro ; given a random number(0-51), decode it as a card ; random MOD 13, quotient is corresponding to suit, and remainder + 1 is ;corresponding to card number ; quotient = 0: diamond 1: club 2: heart 3: spade ; probably can write a macro for the MOD function ; example: mod random, 13, Dsuit3, Dcardnum3, DAce ; @0 @1 @2 @3 @4 .macro mod ldi ZL, LOW(@4) ;st_ram temp2, @4 ldi ZH, HIGH(@4) ld temp2, Z clr temp ratio: cpi @0, @1 brlt remainder subi @0, @1 inc temp rjmp ratio remainder: mov temp1, @0 inc temp1 ace: cpi temp1, 1 brne endm ldi temp2, 1 endm: ldi ZL, LOW(@2) ;ld_ram @2, temp ldi ZH, HIGH(@2) st Z, temp ldi ZL, LOW(@3) ;ld_ram @3, temp1 ldi ZH, HIGH(@3) st Z, temp1 ldi ZL, LOW(@4) ;ld_ram @4, temp2 ldi ZH, HIGH(@4) st Z, temp2 .endmacro ; find out the largest possible hand and store it back to the 2nd parameter ; 1st parameter indicates if the hand has an Ace or not ; 2nd parameter originally stores the normal current hand without ; having the "Ace effect." ; example: AceHand PAce, Phand ; if PAce is 1 and Phand is 11, then after calling AceHand ; Phand is equal to 21; on the other hand, if PAce is 0 or Phand ; is originally greater than 11, then Phand's final value will not be ; changed .macro AceHand ldi ZL, LOW(@1) ;st_ram temp1, @1 ldi ZH, HIGH(@1) ld temp1, Z ldi ZL, LOW(@0) ;st_ram temp2, @0 ldi ZH, HIGH(@0) ld temp2, Z tst temp2 breq noAce cpi temp1, 12 brge noAce subi temp1, -10 ; ldi ZL, LOW(@1) ;ld_ram @1, temp1 ; ldi ZH, HIGH(@1) ; st Z, temp1 noAce: .endmacro .macro tx_text_predefined ;now the pointer to the preset message ldi ZL, LOW(@0<<1) ;ptr to message ldi ZH, HIGH(@0<<1) lpm out UDR, r0 ;fire off the UART transmit ser TXflash ;the string is in flash ser TXbusy ;and set the TX busy flag sbi UCR, UDRIE ;enable the TXempty interrupt rcall TXwait .endmacro .macro tx_text_variable ;now the pointer to the variable message in RAM ldi ZL, LOW(@0) ;ptr to RAM ldi ZH, HIGH(@0) ld r0,Z out UDR, r0 ;fire off the UART transmit clr TXflash ;the string is in RAM ser TXbusy ;and set the TX busy flag sbi UCR, UDRIE ;enable the TXempty interrupt rcall TXwait .endmacro ; prepare string pointers for the prepare_string routine .macro p_pre_string ldi ZL, low(@0) ldi ZH, high(@0) mov param1a, ZL mov param1b, ZH ldi ZL, low(@1) ldi ZH, high(@1) mov param2a, ZL mov param2b, ZH .endmacro