home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 82 / asm / source / crash / run82.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  8.9 KB  |  324 lines

  1. ;Running the Halls
  2. ;By OneBigDoofus ╟:-) 
  3. ;OBD on irc
  4. .nolist
  5. #include "crash82.inc"
  6. .list
  7. .db "Running The Halls v1.2",0
  8.  
  9. ;ported from 82/85 basic game by Harris Novar and David Mazur i think.
  10. ;was never released on net i dont think, and i made it on the 82 a thousand
  11. ;times and optimized it to about 50% of original speed, but now that it is 
  12. ;in asm, it is even faster! if you press 0 at the menu to choose speeds
  13. ;you get about the basic speed, if not faster than that
  14. ;i also added some graphix to make it a little better than text
  15.  
  16. cc1 = TEXT_MEM
  17. cc7 = TEXT_MEM+6
  18. cc8 = TEXT_MEM+7
  19. ccy = TEXT_MEM+8
  20. score = TEXT_MEM+9
  21. delayspeed = TEXT_MEM+30
  22.  
  23.  
  24.  
  25.  
  26.  ROM_CALL(CLEARLCD) 
  27.  ld hl,$0003
  28.  ld (CURSOR_ROW),hl
  29.  ld hl,menu_str
  30.  ROM_CALL(D_ZT_STR)
  31. Menu:
  32.  call CR_KHAND        ;Built in Crash Key handler
  33.  sbc hl,hl        ;hl value is now 0   ;this is used later to figure 
  34.  ld de,2        ;de value is now 2   ;the delay speed
  35.  cp K_0            ;check if the 0 key is pressed
  36.  jr z,speed0        ;if it is pressed, goto speed0
  37.  cp K_1            ;check if the 1 key is pressed
  38.  jr z,speed1         ;if it is pressed, goto speed1
  39.  cp K_2            ;check if the 2 key is pressed
  40.  jr z,speed2        ;if it is pressed, goto speed2
  41.  cp K_3            ;check if the 3 key is pressed
  42.  jr z,speed3        ;if it is pressed, goto speed3
  43.  cp K_4            ;check if the 4 key is pressed
  44.  jr z,speed4        ;if it is pressed, goto speed4
  45.  cp K_5            ;check if the 5 key is pressed
  46.  jr z,speed5        ;if it is pressed, goto speed5
  47.  cp K_6            ;check if the 6 key is pressed
  48.  jr z,speed6        ;if it is pressed, goto speed6
  49.  cp K_7            ;check if the 7 key is pressed
  50.  jr z,speed7         ;if it is pressed, goto speed7
  51.  cp K_YEDIT
  52.  jr z,prevspeed
  53.  cp K_MODE        ;check if the MODE key is pressed
  54.  ret z            ;if it is pressed, return to crash
  55.  jr Menu        ;if none of these buttons were pressed, go back and
  56.             ;check again
  57. prevspeed:
  58.  ld hl,(previousspeed)
  59.  jr speed7
  60. speed0:            ;
  61.  add hl,de        ;hl = hl +2 since de was set to 2 earlier
  62. speed1:
  63.  add hl,de        ;hl = hl +2
  64. speed2:
  65.  add hl,de        ;hl = hl +2
  66. speed3:
  67.  add hl,de        ;hl = hl +2
  68. speed4:
  69.  add hl,de        ;hl = hl +2
  70. speed5:
  71.  add hl,de        ;hl = hl +2
  72. speed6:
  73.  add hl,de        ;hl = hl +2
  74. speed7:
  75.  ld (delayspeed),hl    ;delayspeed is now the value of hl
  76.  ld (previousspeed),hl    ;suggestion from Tim R if you press second, the previous
  77.             ;speed you chose is obtained
  78. loop:
  79.  ld a,100        ;just a random value above 16 to use so you wont get
  80.  ld hl,cc1        ;hit at the beginning, now point hl to cc1
  81.  ld b,8            ;load 8 into b, so it repeats 7 times
  82. loop1:            ;here for djnz, so we can put it 100 into TEXT_MEM+0-7  
  83.  ld (hl),a        ;load a to where hl is pointing, which is TEXT_MEM+7-b
  84.  inc hl            ;point hl to next variable
  85.  djnz loop1        ;dec b \ jr nz,loop1
  86.  call RAND        ;function in crash to put a random number into a
  87.  and %00000111        ;gets last 3 bits, so a is 0-15
  88.  ld (ccy),a        ;puts the value of a, into ccy, which is where you start
  89.  sbc hl,hl         ;
  90.  ld (score),hl        ;puts the score at 0
  91.  
  92. mainloop:
  93. ;This is a small getkey routine, taken from CrASH_Man's sprite test
  94. ;It allows smooth moving, and doesnt start off slow like GET_KEY
  95.   LD  A, $FF \ OUT ($01), A     ; Reset Port
  96.   LD  A, $BF \ OUT ($01), A     ; Mask out MODE and 2nd
  97.   IN  A, ($01)
  98.   BIT 6, A \ jr z,EXIT              ; If MODE pressed, done
  99.   BIT 5, A \ jr z,pause      ; If 2nd pressed, delay
  100.  
  101.   LD  A, $FF \ OUT ($01), A     ; Reset Port
  102.   LD  A, $FE \ OUT ($01), A     ; Mask out Arrows
  103.   IN  A, ($01)
  104.   BIT 1, A \ jr Z, moveleft
  105.   BIT 2, A \ jr Z, moveright 
  106. scroll:                ; Lable here to come back from jumps
  107.  call Scroll_U            ; Scrolls up and puts the you sprite back and a new enemy
  108.  call CR_GRBCopy        ; fast graphbuffer copy; built in crash
  109.  ld a,(ccy)            ; the value @ ccy is now a
  110.  ld hl,cc8            ; hl now points to cc8
  111.  cp (hl)            ; compare a to whats at cc8
  112.  jr z,EXIT            ; if it is the same, you lose, goto exit
  113.  ld hl,(score)            ; hl is the value @ score
  114.  inc hl                ; hl=hl+1
  115.  ld (score),hl            ; put the new hl back in score
  116.  ld a,(delayspeed)        ; the value @ delayspeed is now a
  117.  or a                ; like cp 0, but shorter/faster
  118.  jr z,mainloop            ; if its 0, dont delay any, go back to beginning
  119. delay:                ; takes some time
  120.  call CR_GRBCopy        ; routine takes a while, so it is used to delay game
  121.  dec a \ jr nz,delay        ; a=a-1 if a is not 0, delay longer
  122.  jr mainloop            ; if a is 0, goto beginning
  123.  
  124. moveright:            ; routine to move you right
  125.  ld a,(ccy)            ; put the value @ ccy into a
  126.  cp 15                ; compare a to 15
  127.  jr z,scroll               ; if it is 15, you cant go any farther right, go back
  128.  inc a                ; a=a+1
  129.  ld (ccy),a            ; put a back into ccy
  130.  jr scroll            ; go back
  131. moveleft:
  132.  ld a,(ccy)            ; put the value @ccy into a
  133.  or a                ; like cp 0, but shorter/faster
  134.  jr z,scroll               ; if it is 0, go back
  135.  dec a                ; a=a-1
  136.  ld (ccy),a            ; put a back into ccy
  137.  jr scroll            ; go back    
  138. pause:
  139.  call GET_KEY           ; reset keyport so it doesnt goto 2nd already
  140.  LD  HL,$0903                ; set up the coords for displaying the score
  141.  LD  (CURSOR_ROW),HL        
  142.  ld hl,(score)            ; put score in hl
  143.  ROM_CALL(D_HL_DECI)        ; display the score
  144.  call CR_KHAND            ; uncrashable KHAND, lets you 
  145.  cp K_MODE            ; if mode is pressed,                 ; 
  146.  jr z,EXIT            ; quit
  147.  call GET_KEY            ; reset keyport
  148.  call CR_GRBcopy
  149.  jp mainloop            ; go back
  150.  
  151. EXIT:
  152.  LD  HL,$0903                ; set up the coords for displaying the score
  153.  LD  (CURSOR_ROW),HL        
  154.  ld hl,(score)            ; put score in hl
  155.  ROM_CALL(D_HL_DECI)        ; display the score
  156.  LD  HL,$0303               ; set up coords for displaying "Score:"
  157.  LD  (CURSOR_ROW),HL        ; 
  158.  ld hl,score_str        ; write "score:"    
  159.  ROM_CALL(D_ZT_STR)        ; function to do it
  160.  ld hl,$0404            ; new coords to write "High:"
  161.  ld (CURSOR_ROW),HL
  162.  ld hl,high_str
  163.  ROM_CALL(D_ZT_STR)        ; display "High:"
  164.  ld a,(delayspeed)        ; used to determine where the highscore is
  165.  ld hl,high7-1            ; hl is 
  166.  inc a
  167. highloop:
  168.  inc hl
  169.  dec a
  170.  jr nz, highloop
  171.  push hl
  172.  call LD_HL_MHL
  173.  push hl
  174.  ld de,(score)
  175.  call CP_HL_DE
  176.  jr c,newhigh
  177.  pop hl
  178.  ROM_CALL(D_HL_DECI)
  179.  pop de
  180.  jr wait
  181. newhigh:
  182.  pop hl \ pop de
  183.  ld hl,score
  184.  ldi
  185.  ldi
  186.  dec hl \ dec hl
  187.  call LD_HL_MHL
  188.  ROM_CALL(D_HL_DECI)
  189. wait:
  190.  call CR_KHAND 
  191.  cp K_LEFT
  192.  jr z,wait
  193.  cp K_RIGHT
  194.  jr z,wait
  195.  cp K_MODE
  196.  jr z,wait
  197.  ret
  198.  
  199. Scroll_U:                       ; [16228 Clock Cycles]-- 63 less now that i took out the pushes and pops
  200.   LD  HL, GRAPH_MEM+96          ; Copy from one row below top
  201.   LD  DE, GRAPH_MEM             ;   to top row
  202.   LD  BC, 672                   ;   672 bytes
  203.   LDIR                          ; another routine by Crash man
  204.   LD HL,GRAPH_MEM+672
  205.   LD DE,GRAPH_MEM+673
  206.   LD BC,108
  207.   LD A,0
  208.   LD (HL),A
  209.   LDIR
  210. putyou:            ;puts a little guy on the screen
  211.  ld a,(ccy)        ;puts value of ccy into a
  212.  ld ix, you
  213.  ld  c,0             ;y coord is always 0
  214.  call DrwSpr
  215. movevars:
  216.  ld bc,7
  217.  ld hl,cc7
  218.  ld de,cc8
  219.  lddr           ; i cannot use ldir here so i use lddr
  220.  call RAND    ;
  221.  and 15        ;0-15
  222.  ld (cc1),a
  223. putenmy:                ;puts enemy
  224.  call RAND              ;put in second enemy two get rid of a little bit of monotony
  225.  and 1          ; between 0-1; only works for numbers that are powers of 2
  226.  or a           ; equivalent to cp 0; but faster and shorter
  227.  ld c,56
  228.  jr z,penmy2
  229.  ld a,(cc1)
  230.  ld ix, enmy1
  231.  jr DrwSpr 
  232. penmy2:
  233.  ld a,(cc1) 
  234.  ld ix, enmy2
  235. DrwSpr:        ;great sprite routine by crash man, slightly modified for RTH
  236.   LD  d, a    ;do x*6+1
  237.   ADD a, a    ;x=2x
  238.   ADD a, d    ;x=x+OX(original x)   or x*3
  239.   add a, a    ;x=2x
  240.   inc a
  241.   LD  H, 0 \ LD  L, C           ; Do y*12
  242.   LD  B, H
  243.   ADD HL, HL \ ADD HL, BC       ; y=y*3
  244.   ADD HL, HL \ ADD HL, HL       ;  =y*12
  245.   LD  C, A                      ; Do x/4
  246.   SRL C \ SRL C \ SRL C
  247.   ADD HL, BC
  248.  
  249.   LD  BC, GRAPH_MEM \ ADD HL, BC ; Add address to graphbuf
  250.  
  251.   AND %00000111                 ; Get the remainder of x/8
  252.   LD  E, 7                      ; Line loop
  253.   LD  D, A                      ; B=how many bits to shift each line
  254. _DS_LineLoop:
  255.   LD  B, D                      ; Shift loop
  256.   LD  A, (IX+0)                 ; Get sprite data
  257.   LD  C, 0
  258. _DS_ShiftLoop:
  259.   RRA \ RR  C                   ; Shift Sprite Line
  260.   DJNZ _DS_ShiftLoop
  261.   INC IX                        ; Inc spritepointer
  262.   OR (HL) \ LD  (HL), A        ; Write line to graphbuf
  263.   INC HL
  264.   LD  A, C
  265.   OR (HL) \ LD  (HL), A
  266.   LD  BC, 11                    ; Calculate next line address
  267.   ADD HL, BC
  268.   DEC E
  269.   JR  NZ, _DS_LineLoop          ; Next line
  270.   RET
  271.  
  272.  
  273. previousspeed:
  274.  .dw 0
  275. high7:
  276.  .dw 0
  277. high6:
  278.  .dw 0
  279. high5:
  280.  .dw 0
  281. high4:
  282.  .dw 0
  283. high3:
  284.  .dw 0
  285. high2:
  286.  .dw 0
  287. high1:
  288.  .dw 0
  289. high0:
  290.  .dw 0
  291. you:
  292.  .db %01110000
  293.  .db %01010000
  294.  .db %01110000
  295.  .db %11111000
  296.  .db %01110000
  297.  .db %01010000
  298.  .db %01010000
  299. enmy1:
  300.  .db %01110000
  301.  .db %11111000
  302.  .db %10101000
  303.  .db %11111000
  304.  .db %01110000
  305.  .db %01010000
  306.  .db %01110000
  307. enmy2:
  308.  .db %01110000
  309.  .db %10101000
  310.  .db %10101000
  311.  .db %01110000
  312.  .db %01110000
  313.  .db %11011000
  314.  .db %01110000
  315.  
  316. menu_str:
  317.  .db "Enter Speed: 0-7",0
  318.  
  319.  
  320. score_str:
  321.  .db "Score:",0
  322. high_str:
  323.  .db "High:",0
  324.