home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 86 / asm / source / war86.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  11.0 KB  |  584 lines

  1. #include "ti86asm.inc"
  2. #include "asm86.h"
  3.  
  4. .org _asm_exec_ram
  5.  
  6. begin:
  7.     call _clrLCD
  8.     ld a,0
  9.     ld (p1_pos),a
  10.     call dispp1
  11.     ld a,7
  12.     ld (p2_pos),a
  13.     call dispp2
  14.     ld a,0
  15.     ld (shot1),a
  16.     ld (shot2),a
  17.     ld a,10
  18.     ld (hit1),a
  19.     ld (hit2),a
  20.     call _runindicoff
  21.     ld hl,menu_table
  22.  
  23. ;===========================================================
  24. ; DoMenu -- Bar menu routine
  25. ; Clears the screen and displays a table driven bar menu
  26. ;  
  27. ;      A       CCCC   ZZZZZ
  28. ;     A A     C           ZZ
  29. ;    AAAAA    C        ZZ
  30. ;   A     A    CCCC   ZZZZZ
  31. ;
  32. ;     Welcom fellow coder to the routines of the ACZ...
  33. ; Assembly Coders Zenith is a new group that will further TI
  34. ; assembly programming on all platforms.  This is the first
  35. ; released routine from one of their up comming games and it
  36. ; will not be the last.  Be ready for us, here we come...
  37. ; CLEM, Dux Gregis, Dave Scheltema, David Phillips, and Jbrett.
  38. ;
  39. ;
  40. ; Coded by: 
  41. :          David Phillips <electrum@tfs.net> aka Electrum
  42. ;            David Scheltema <scheltem@aaps.k12.mi.us> aka zoomBlock
  43. ;
  44. ; input: HL = menu table
  45. ; output: chosen table address jumped to
  46. ;
  47. ; example table:
  48. ;  .db 2                ; num entries
  49. ;  .dw "My menu",0        ; title text (at the top)
  50. ;  .dw "First thing",0    ; text for each entry
  51. ;  .dw "Second one",0    ; ...
  52. ;  .dw Option1            ; pointers (labels) to jump
  53. ;  .dw Option2            ; to for each entry in menu
  54. ;
  55. ; Note: routine must be jumped to!
  56. ;===========================================================
  57. DoMenu:
  58.  push hl                    ; _clrLCD destroys hl
  59.  call _clrLCD                ; clears the screen
  60.  pop hl                        ; now restore it
  61.  ld c,(hl)                    ; get number of entries
  62.  inc hl                        ; move to menu title text
  63.  ld de,$0001                ; draw at top, one char right
  64.  ld    (_penCol),de            ; set the small font coords
  65.  call _vputs                ; print the title text
  66.  push hl                    ; save pointer
  67.  ld hl,$fc00                ; point to video ram
  68.  call DoMenuInv                ; invert the top line
  69.  pop hl                        ; restore our pointer
  70.  ld b,c                        ; load num entries for loop
  71.  ld de,$0729                ; start printing at middle of second line
  72. DoMenuDTL:
  73.  ld (_penCol),de            ; set the font coords
  74.  call _vputs                ; print the menu text
  75.  ld a,d                        ; get the vertical coord
  76.  add a,7                    ; move to next line
  77.  ld d,a                        ; save new coord
  78.  djnz DoMenuDTL                ; draw all the text
  79.  push hl                     ; save pointer
  80.  ld b,1                        ; start menu at first entry
  81.  call DoMenuInvBar            ; invert it
  82. DoMenuL:
  83.  push bc                    ; save entries and current entry
  84.  call _getky                ; same as GET_KEY
  85.  pop bc                        ; restore it
  86.  cp K_UP                    ; did they press up?
  87.  jr z,DoMenuUp                ; move menu bar up
  88.  cp K_DOWN                    ; or was it down?
  89.  jr z,DoMenuDown            ; then move the bar down
  90.  cp K_SECOND                ; did they hit 2nd?
  91.  jr z,DoMenuSelect            ; then they want it
  92.  cp K_ENTER                    ; some people like enter
  93.  jr z,DoMenuSelect            ; so check it too
  94.  jr DoMenuL                    ; they're just sitting there, loop again
  95. DoMenuUp:
  96.  call DoMenuInvBar            ; invert current selection back to normal
  97.  dec b                        ; move up
  98.  jr nz,DoMenuBar            ; if it's zero, we're at the top
  99.  ld b,c                        ; so move to the bottom
  100.  jr DoMenuBar                ; handle menu bar
  101. DoMenuDown:
  102.  call DoMenuInvBar            ; same as up, go back to normal text
  103.  ld a,c                        ; get current entry for check
  104.  cp b                        ; at the bottom?
  105.  jr z,DoMenuDownT            ; the move to the top
  106.  inc b                        ; move down
  107.  jr DoMenuBar                ; handle menu bar
  108. DoMenuDownT:
  109.  ld b,1                        ; move to the top
  110. DoMenuBar:
  111.  call DoMenuInvBar            ; invert the new selection
  112.  jr DoMenuL                    ; now it's time to loop
  113. DoMenuInvBar:
  114.  push hl                    ; save pointer
  115.  push bc                    ; save position and entries
  116.  ld h,b                        ; get position
  117.  ld l,112                    ; there are 7 lines of 16 bytes each (7*16 = 112)
  118.  call MUL_HL                ; do the multiply
  119.  ld de,$fc00                ; we need to add to video memory
  120.  add hl,de                    ; do the add
  121.  call DoMenuInv                ; invert the line
  122.  pop bc                        ; restore position and entries
  123.  pop hl                        ; restore pointer
  124.  ret                        ; done inverting
  125. DoMenuInv:
  126.  ld b,7*16                    ; each row is 16 bytes wide and text is 7 rows high
  127. DoMenuIL:
  128.  ld a,(hl)                    ; get the byte
  129.  cpl                        ; NOT the byte--flips all the bits
  130.  ld (hl),a                    ; save the new byte
  131.  inc hl                        ; next byte
  132.  djnz DoMenuIL                ; loop for all bytes
  133.  ret                        ; we're done with the invert loop
  134. DoMenuSelect:
  135.  pop hl                        ; restore the pointer
  136.  ld d,0                        ; clear upper byte
  137.  ld e,b                        ; load lower byte with current selection
  138.  dec e                        ; decrease, starting at 0 instead of 1
  139.  sla e                        ; multiply by 2, pointers are 16-bit (2 bytes)
  140.  add hl,de                    ; add to get correct address in the jump table
  141.  ld a,(hl)                    ; get lower byte of pointer
  142.  inc hl                        ; next byte
  143.  ld h,(hl)                    ; get upper byte of pointer
  144.  ld l,a                        ; complete pointer with lower byte
  145.  jp (hl)                    ; jump to the address from the table--hl, not (hl
  146.     
  147. loop1:
  148.     call _clrScrn
  149.     ld b,0
  150.     ld c,10
  151.     ld (_penCol),bc
  152.     ld a,(hit1)
  153.     call dispa
  154.     ld c,106
  155.     ld (_penCol),bc
  156.     ld a,(hit2)
  157.     call dispa
  158. loop:
  159.     call dispp1
  160.     call dispp2
  161.     call GET_KEY
  162.     cp K_GRAPH
  163.     jr z,down1
  164.     cp K_SECOND
  165.     jr z,up1
  166.     cp K_STO
  167.     jp z,shoot1
  168.     cp K_PLUS
  169.     jp z,down2
  170.     cp K_STAR
  171.     jp z,up2
  172.     cp K_F5
  173.     jp z,shoot2
  174.     cp K_EXIT
  175.     jp z,begin
  176.     ld a,(shot1)
  177.     cp 1
  178.     jp z,inc_shot_1
  179. loop2:    
  180.     ld a,(shot2)
  181.     cp 1
  182.     jp z,inc_shot_2
  183.     jr loop
  184.  
  185. dispa:
  186.       ld l,a
  187.     ld h,0
  188.     xor a
  189.       ld de,-1
  190.       ld (_curRow),de
  191.      call 4A33h
  192.     dec hl
  193.     jp _vputs
  194.  
  195. dispp1:
  196.     ld e,0
  197.     ld a,(p1_pos)
  198.     ld d,a
  199.     ld hl,$fc00
  200.     ld bc,player1
  201.     call GridPutSprite
  202.     ret    
  203. dispp2:
  204.     ld e,15
  205.     ld a,(p2_pos)
  206.     ld d,a
  207.     ld hl,$fc00
  208.     ld bc,player2
  209.     call GridPutSprite
  210.     ret
  211.  
  212. down1:
  213.     ld a,(p1_pos)
  214.     cp 7
  215.     jp z,loop
  216.     ld e,0
  217.     call draw_blank1
  218.     ld a,(p1_pos)
  219.     inc a
  220.     ld (p1_pos),a
  221.     call dispp1
  222.     jp loop
  223. up1:
  224.     ld a,(p1_pos)
  225.     cp 0
  226.     jp z,loop
  227.     ld e,0
  228.     call draw_blank1
  229.     ld a,(p1_pos)
  230.     dec a
  231.     ld (p1_pos),a
  232.     call dispp1
  233.     jp loop
  234.  
  235. draw_blank1:
  236.     ld d,a
  237.     ld bc,blank
  238.     ld hl,$fc00
  239.     call GridPutSprite
  240.     ret
  241.  
  242. down2:
  243.     ld a,(p2_pos)
  244.     cp 7
  245.     jp z,loop
  246.     ld e,15
  247.     call draw_blank1
  248.     ld a,(p2_pos)
  249.     inc a
  250.     ld (p2_pos),a
  251.     call dispp2
  252.     jp loop
  253. up2:
  254.     ld a,(p2_pos)
  255.     cp 0
  256.     jp z,loop
  257.     ld e,15
  258.     call draw_blank1
  259.     ld a,(p2_pos)
  260.     dec a
  261.     ld (p2_pos),a
  262.     call dispp2
  263.     jp loop
  264.  
  265. shoot1:
  266.     ld a,(shot1)
  267.     cp 1
  268.     jp z,loop
  269.     ld a,1
  270.     ld (shot1),a
  271.     ld a,(p1_pos)
  272.     ld (shot1v),a
  273.     ld d,a
  274.     ld a,1
  275.     ld (shot1h),a
  276.     ld e,a
  277.     ld bc,fire1
  278.     ld hl,$fc00
  279.     call GridPutSprite
  280.     ld a,0
  281.     ld (s1),a
  282.     jp loop2
  283. inc_shot_1:
  284.     ld a,(s1)
  285.     cp 150
  286.     jr c,inc1
  287.     ld a,0
  288.     ld (s1),a
  289.     ld a,(shot1h)
  290.     cp 15
  291.     jr z,no_shot1
  292.     ld a,(shot1v)
  293.     ld d,a
  294.     ld a,(shot1h)
  295.     ld e,a
  296.     ld bc,blank
  297.     ld hl,$fc00
  298.     call GridPutSprite
  299.     ld a,(shot1v)
  300.     ld d,a
  301.     ld a,(shot1h)
  302.     inc a
  303.     ld (shot1h),a
  304.     ld e,a
  305.     ld bc,fire1
  306.     ld hl,$fc00
  307.     call GridPutSprite
  308.     jp loop2
  309. no_shot1:
  310.     ld a,(shot1v)
  311.     ld b,a
  312.     ld a,(p2_pos)
  313.     cp b
  314.     jp z,one_hit_2
  315.     ld a,(shot1v)
  316.     ld d,a
  317.     ld a,(shot1h)
  318.     ld e,a
  319.     ld bc,blank
  320.     ld hl,$fc00
  321.     call GridPutSprite
  322.     ld a,0
  323.     ld (shot1),a
  324.     jp loop2
  325. inc1:
  326.     inc a
  327.     ld (s1),a
  328.     jp loop2
  329.  
  330. shoot2:
  331.     ld a,(shot2)
  332.     cp 1
  333.     jp z,loop
  334.     ld a,1
  335.     ld (shot2),a
  336.     ld a,(p2_pos)
  337.     ld (shot2v),a
  338.     ld d,a
  339.     ld a,14
  340.     ld (shot2h),a
  341.     ld e,a
  342.     ld bc,fire1
  343.     ld hl,$fc00
  344.     call GridPutSprite
  345.     ld a,0
  346.     ld (s2),a
  347.     jp loop
  348. inc_shot_2:
  349.     ld a,(s2)
  350.     cp 150
  351.     jr c,inc2
  352.     ld a,0
  353.     ld (s2),a
  354.     ld a,(shot2h)
  355.     cp 0
  356.     jr z,no_shot2
  357.     ld a,(shot2v)
  358.     ld d,a
  359.     ld a,(shot2h)
  360.     ld e,a
  361.     ld bc,blank
  362.     ld hl,$fc00
  363.     call GridPutSprite
  364.     ld a,(shot2v)
  365.     ld d,a
  366.     ld a,(shot2h)
  367.     dec a
  368.     ld (shot2h),a
  369.     ld e,a
  370.     ld bc,fire1
  371.     ld hl,$fc00
  372.     call GridPutSprite
  373.     jp loop
  374. no_shot2:
  375.     ld a,(shot2v)
  376.     ld b,a
  377.     ld a,(p1_pos)
  378.     cp b
  379.     jp z,two_hit_1
  380.     ld a,(shot2v)
  381.     ld d,a
  382.     ld a,(shot2h)
  383.     ld e,a
  384.     ld bc,blank
  385.     ld hl,$fc00
  386.     call GridPutSprite
  387.     ld a,0
  388.     ld (shot2),a
  389.     jp loop
  390. inc2:
  391.     inc a
  392.     ld (s2),a
  393.     jp loop
  394.  
  395. two_hit_1:
  396.     ld a,(hit1)
  397.     dec a
  398.     ld (hit1),a
  399.     cp 0
  400.     jr z,fight_over
  401.     ld a,0
  402.     ld (shot2),a
  403.     jp loop1
  404. one_hit_2:
  405.     ld a,(hit2)
  406.     dec a
  407.     ld (hit2),a
  408.     cp 0
  409.     jr z,fight_over
  410.     ld a,0
  411.     ld (shot1),a
  412.     jp loop1
  413.  
  414. fight_over:
  415.     ld a,(hit2)
  416.     cp 0
  417.     jr z,fo1
  418.     ld a,(hit1)
  419.     cp 0
  420.     jr z,fo2
  421. fo1:
  422.     ld hl,p1_wins
  423.     jr over
  424. fo2:
  425.     ld hl,p2_wins
  426. over:
  427.     call _homeup
  428.     call _puts
  429.     call $4d43
  430.     jp begin
  431. exit:    
  432.     call _clrLCD
  433.     call _homeup
  434.     ret
  435.  
  436. keys:
  437.     call _clrScrn
  438.     call _flushallmenus
  439.     call _homeup
  440.     ld hl,keys_text
  441.     call _puts
  442.     ld a,01ch
  443.     call _putc
  444.     call $4d43
  445.     call _clrLCD
  446.     call _homeup
  447.     ld hl,keys_text2
  448.     call _puts
  449.     call $4d43
  450.     jp begin
  451.  
  452. ;=====================================================================
  453. ; GridPutSprite:
  454. ;  Puts an aligned sprite at (E, D), where BC -> Sprite
  455. ;=====================================================================
  456. ; IN : D  = y (0-7 inclusive)
  457. ;      E  = x (0-15 inclusive)
  458. ;      BC -> sprite
  459. ;      HL -> screen buffer to draw to ($fc00)
  460. ;
  461. ; OUT: AF, BC, DE, HL modified
  462. ; Current total : 44b/289t (not counting ret)
  463. ;=====================================================================
  464. GridPutSprite:
  465.  srl d          ; de = 128y+x (16 bytes/row, 8 rows)
  466.  rra
  467.  and $80
  468.  or e           ; add x offset (remember x <= 15)
  469.  ld e,a
  470.  add hl,de      ; hl-> address + offset
  471.  ld de,$10      ; initialize line increment
  472.  ld a,(bc)      ; get byte from sprite
  473.  ld (hl),a      ; put byte on screen
  474.  inc bc         ; move to next byte in sprite
  475.  add hl,de      ; move to next line on screen
  476.  ld a,(bc)      ; {2}
  477.  ld (hl),a      ; ...
  478.  inc bc         ; ..
  479.  add hl,de      ; .
  480.  ld a,(bc)      ; {3}
  481.  ld (hl),a      ; ...
  482.  inc bc         ; ..
  483.  add hl,de      ; .
  484.  ld a,(bc)      ; {4}
  485.  ld (hl),a      ; ...
  486.  inc bc         ; ..
  487.  add hl,de      ; .
  488.  ld a,(bc)      ; {5}
  489.  ld (hl),a      ; ...
  490.  inc bc         ; ..
  491.  add hl,de      ; .
  492.  ld a,(bc)      ; {6}
  493.  ld (hl),a      ; ...
  494.  inc bc         ; ..
  495.  add hl,de      ; .
  496.  ld a,(bc)      ; {7}
  497.  ld (hl),a      ; ...
  498.  inc bc         ; ..
  499.  add hl,de      ; .
  500.  ld a,(bc)      ; {8}
  501.  ld (hl),a      ; ...
  502.  ret
  503.  
  504. p1_wins:    .db "Player 1 wins!",0
  505. p2_wins:    .db "Player 2 wins!",0
  506.  
  507. keys_text:
  508.     .db "Player 1:            "
  509.     .db "                     "
  510.     .db "UP................2ND"
  511.     .db "DOWN.............GRPH"
  512.     .db "SHOOT...............",0
  513. keys_text2:
  514.     .db "Player 2:            "
  515.     .db "                     "
  516.     .db "UP..................*"
  517.     .db "DOWN................+"
  518.     .db "SHOOT..............F5",0
  519.  
  520. p1_pos: .db 0
  521. p2_pos:    .db 0
  522. shot1:    .db 0
  523. shot1v:    .db 0
  524. shot1h:    .db 0
  525. s1:        .db 0
  526. shot2:    .db 0
  527. shot2v:    .db 0
  528. shot2h:    .db 0
  529. s2:        .db 0
  530. hit1:    .db 0
  531. hit2:    .db 0
  532.  
  533. menu_table:
  534.     .db 3
  535.     .db "                                    WAR86!",0
  536.     .db "Play",0
  537.     .db "Keys",0
  538.     .db "Exit",0
  539.     .dw loop1
  540.     .dw keys
  541.     .dw exit
  542.  
  543. player1:
  544.     .db %10011000
  545.     .db %11011000
  546.     .db %11111100
  547.     .db %11111011
  548.     .db %11111011
  549.     .db %11111100
  550.     .db %11011000
  551.     .db %10011000
  552.  
  553. player2:
  554.     .db %00011001
  555.     .db %00011011
  556.     .db %00111111
  557.     .db %11011111
  558.     .db %11011111
  559.     .db %00111111
  560.     .db %00011011
  561.     .db %00011001
  562.  
  563. blank:
  564.     .db %00000000
  565.     .db %00000000
  566.     .db %00000000
  567.     .db %00000000
  568.     .db %00000000
  569.     .db %00000000
  570.     .db %00000000
  571.     .db %00000000
  572.  
  573. fire1:
  574.     .db %00000000
  575.     .db %00000000
  576.     .db %00000000
  577.     .db %11111111
  578.     .db %00000000
  579.     .db %00000000
  580.     .db %00000000
  581.     .db %00000000
  582.  
  583. .end
  584.