home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 85 / asm / source / routines / mkt.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  6.4 KB  |  347 lines

  1. ; -------------- Multi Key Test ----------------
  2. ;   (c) PASCAL BOURON , bouron@ens-cachan.fr
  3. ; ----------------------------------------------
  4. ;
  5. ; For several games, ( 2 players game , game
  6. ; with 8 directions move, or fire with movement)
  7. ; you must test if two (or plus) key is pressed
  8. ; So I have do this small example for show how
  9. ; you can do that. I test also if a byte is
  10. ; receive in the link port ( If you want do
  11. ; a game with 4 players (2 TI))
  12. ;
  13. ; I test exit,F1,F2,F3,F4,F5
  14. ;
  15. ; To quit press exit or send a $00 in the link port
  16. ;
  17. ;
  18. ; If you have questions or suggestions e-mail me.
  19. ;
  20. #INCLUDE "TI-85.H"
  21. ;-------------------------------------------
  22. ; Program data stored in text memory (80DF)
  23. ;-------------------------------------------
  24. x        =$80DF
  25. error_nb =$80E0
  26. bit      =$80E1
  27. counter  =$80E2
  28. last     =$80E3
  29. ;---------------------------------------------
  30. ; Program Title
  31. ;---------------------------------------------
  32.  
  33. .org 0
  34. .db " Multi-Key Test by BP",0
  35.  
  36.  
  37.   ROM_CALL(CLEARLCD)
  38.   ld    de,(PROGRAM_ADDR)
  39.   ld    hl,Titre
  40.   add   hl,de
  41.   ROM_CALL(D_ZT_STR)
  42. ;
  43. key_loop1:
  44.   call GET_KEY            ; Classic call ...
  45.   or    a                 ; set flag
  46.   jr    z, key_loop1
  47.         DI
  48.   cp    $37               ; Exit pressed ?
  49.   jr    nz,no_key
  50.  
  51. ;-======================-
  52. ;        Exit
  53. ;-======================-
  54. exit:
  55.         EI
  56.   RET
  57. ;------------------------
  58.  
  59.  
  60. no_key:
  61.         ROM_CALL(CLEARLCD)
  62. wait_key:
  63.   CALL_(Read_byte)
  64.   ld a,(error_nb)
  65.   cp   1
  66.   jr z,next2
  67.   ld   a,(x)
  68.  
  69. ;----------------------------------------------------
  70. ; You can do some actions with the value
  71. ; of the received byte .
  72. ; Here , if it's a $00 : exit
  73. ;
  74. ; Put your different test here :
  75. ;       cp   value
  76. ;       jr   z, routine
  77.   cp   0
  78.   jr   z, exit
  79. ;
  80. ;
  81. ;
  82. ;
  83. ;
  84. ;
  85. ;---------------------------------------------------
  86. next2:
  87.   ld   hl,$0000
  88.   ld   (CURSOR_ROW),hl
  89.   ld   a,$BF              ; $BF = 1011 1111b
  90.   out (1),a
  91.   in a,(1)                ;
  92.   cp $ff                  ; A key is pressed  ?
  93.   jr z,no_key             ;
  94.  
  95. ;Bit 6
  96.         in a,(1)
  97.   bit 6,a                 ; bit 6 => EXIT
  98.   jr  z,exit
  99.  
  100.        ld  b,a
  101.        ld  a,(last)
  102.        cp  b
  103.        jr z,wait_key
  104.        ROM_CALL(CLEARLCD)
  105.        ld a,b
  106.        ld (last),a
  107.  
  108. ;Bit 7
  109.   in a,(1)
  110.   bit 7,a                 ; bit 7 => MORE
  111.   CALL_Z(kp_more)
  112.  
  113.  
  114.  
  115. ;Bit 5
  116.   in a,(1)
  117.   bit 5,a                 ; bit 5 => 2NDE
  118.   CALL_Z(kp_2nd)
  119.  
  120. ;Bit 4
  121.   in a,(1)
  122.   bit 4,a                 ; bit 4 => F1
  123.   CALL_Z(kp_f1)
  124.  
  125. ;Bit 3
  126.   in a,(1)
  127.   bit 3,a                 ; bit 3 => F2
  128.   CALL_Z(kp_f2)
  129.  
  130. ;Bit 2
  131.   in a,(1)
  132.   bit 2,a                 ; bit 2 => F3
  133.   CALL_Z(kp_f3)
  134.  
  135. ;Bit 1
  136.   in a,(1)
  137.   bit 1,a                 ; bit 1 => F4
  138.   CALL_Z(kp_f4)
  139.  
  140. ;Bit 0
  141.   in a,(1)
  142.   bit 0,a                 ; bit 0 => F5
  143.   CALL_Z(kp_f5)
  144.  
  145. ; -------------- end of the tests --------
  146. bit_end:
  147.   JUMP_(wait_key)
  148.  
  149.  
  150. ;-==============================================-
  151. ;                   ACTIONS
  152. ;-==============================================-
  153. kp_more :
  154.         ld    a,0
  155.   ld   (CURSOR_ROW),a
  156.         ld    a,0
  157.   ld   (CURSOR_COL),a
  158.   ld    de,(PROGRAM_ADDR)
  159.   ld    hl,data
  160.   add   hl,de
  161.   ROM_CALL(D_ZT_STR)
  162.   ret
  163. kp_2nd :
  164.         ld    a,1
  165.   ld   (CURSOR_ROW),a
  166.         ld    a,0
  167.   ld   (CURSOR_COL),a
  168.         ld    hl,8
  169.   ld    de,(PROGRAM_ADDR)
  170.         add   hl,de
  171.   ld    de,data
  172.   add   hl,de
  173.   ROM_CALL(D_ZT_STR)
  174.   ret
  175. kp_f1 :
  176.         ld  l,$10
  177.         jr  kp_f
  178. kp_f2 :
  179.         ld  l,$14
  180.         jr  kp_f
  181. kp_f3 :
  182.         ld  l,$18
  183.         jr  kp_f
  184. kp_f4 :
  185.         ld  l,$1C
  186.         jr  kp_f
  187. kp_f5 :
  188.         ld  l,$20
  189. kp_f:
  190.         ld  a,l
  191.         sub $10
  192.         rr  a
  193.         rr  a
  194.         and $7
  195.         add a,3
  196.   ld   (CURSOR_ROW),a
  197.         ld    a,0
  198.   ld   (CURSOR_COL),a
  199.         ld  h,0
  200.   ld    de,(PROGRAM_ADDR)
  201.         add   hl,de
  202.   ld    de,data
  203.   add   hl,de
  204.   ROM_CALL(D_ZT_STR)
  205.   ret
  206.  
  207. data:
  208. .db     "MORE   ",0
  209. .db     "2 nde  ",0
  210. .db     "F1 ",0
  211. .db     "F2 ",0
  212. .db     "F3 ",0
  213. .db     "F4 ",0
  214. .db     "F5 ",0
  215.  
  216. ;-===========================================-
  217. ;            Read_byte
  218. ;-===========================================-
  219. ; INPUT   : no
  220. ; OUTPUT  :(x)          =Read byte value
  221. ;          (error_nb)   =# of the error
  222. ; MODIFIED:(bit)
  223. ;          (counter)
  224.  
  225. Read_byte:
  226.     push af
  227.     push bc
  228.     push de
  229.     push hl
  230.     ld    a,1       ; for the OR
  231.     ld    (bit),a
  232.     ld    a,0       ; byte receive
  233.     ld    (x),a
  234.     ld    a,8       ; counter
  235.     ld (counter),a
  236.     ld    a,$C0
  237.     out   (7),a
  238. rb_Loop_wait_1st_bit:
  239.     jr rb_Loop_wait_bit
  240. rb_Loop_wait_bit2:
  241.     ld a,b
  242.     ld (counter),a
  243. rb_Loop_wait_bit:
  244.     ld      d,$10   ; timer
  245. rb_w_Start:
  246.     in    a,(7)
  247.     and 3
  248.     cp  3
  249.     jr    nz,rb_get_bit
  250.     CALL_(rb_delay)
  251.     dec   d                 ;d=0 => erreur
  252.     jr    nz,rb_w_Start     ;Attend le un bit
  253.     ld    a,1
  254.     jr    rb_error
  255. rb_Loop_tmp:
  256.     jr rb_Loop_wait_bit2
  257. rb_get_bit:
  258.     cp    2
  259.     jr    z,rb_receive_zero
  260.     ld    a,(bit)
  261.     ld    e,a
  262.     ld    a,(x)
  263.     or    e
  264.     ld    (x),a
  265.     ld    a,$D4
  266.     out   (7),a
  267.     ld      d,$10
  268. rb_wait_Stop1:
  269.     in    a,(7)
  270.     and 2
  271.     cp  2
  272.     jr    z,rb_suite_receive
  273.     CALL_(rb_delay)
  274.     dec   d
  275.     jr    nz,rb_wait_Stop1
  276.               ; If error ...
  277.     ld    a,2
  278. rb_error:
  279.     ld (error_nb),a
  280.     ld    a,$C0
  281.     out   (7),a
  282.     jr rb_fin
  283.  
  284. rb_receive_zero:
  285.     ld    a,$E8
  286.     out   (7),a
  287.     ld      d,$10
  288. rb_wait_Stop0:
  289.     in    a,(7)
  290.     and 1
  291.     cp  1
  292.     jr    z,rb_suite_receive
  293.     CALL_(rb_delay)
  294.     dec   d
  295.     jr    nz,rb_wait_Stop0
  296.           ; If error ...
  297.     ld a,3
  298.     jr rb_error
  299.  
  300. rb_suite_receive:
  301.     ld a,$c0
  302.     out   (7),a
  303.     ld    a,(bit)
  304.     add   a,a
  305.     ld    (bit),a
  306.     ld a,(counter)
  307.     ld b,a
  308.     djnz    rb_Loop_tmp
  309.     ld      a,$FF                   ; No error
  310.     ld      (error_nb),a
  311. rb_fin:
  312.     pop hl
  313.     pop de
  314.     pop bc
  315.     pop af
  316.     ret
  317.  
  318.  
  319. ;
  320. ;   DELAY
  321. ;
  322. rb_delay:
  323.   push af
  324.   push bc
  325.        ld bc, $80
  326. rb_delayLoop:
  327.        dec bc
  328.        ld a, b
  329.        or c
  330.        jr nz, rb_delayLoop
  331.   pop bc
  332.   pop af
  333.   ret
  334.  
  335.  
  336. Titre:
  337. .db    "                     "
  338. .db    "    Multi Key Test   "
  339. .db    " (c) Pascal Bouron   "
  340. .db    "                     "
  341. .db    " Press a key,then :  "
  342. .db    "Try F1 F2 F3 F4 F5   "
  343. .db    "    2nd and more.",0
  344.  
  345. .END
  346.  
  347.