Advertisement
NovaYoshi

old version of FastEddie83+

May 26th, 2011
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;#SECTION "MAIN", CODE
  2.  
  3. ; A port of the Atari 2600
  4. ; game Fast Eddie for TI-83+
  5. ; by NovaSquirrel
  6. ;
  7. ; refer to the X11 license
  8. ; for sourcecode usage info
  9. VARS equ    appData           ; Unprotected vars
  10. PROT equ    appData + 130     ; Vars protected from new levels
  11. FCA equ PROT                  ; Frame counter
  12. PLX equ FCA + 1               ; Player position X
  13. PLY equ PLX + 2               ; Player position Y
  14. VLX equ VARS + 2              ; Player velocity X, unused
  15. VLY equ VLX + 2               ; Player velocity Y
  16. LAD equ VLY + 2               ; Ladder movement
  17. SCR equ LAD + 2               ; Was gonna be for scroll amount
  18. INSXY equ   SCR + 2           ; Insulin X and Y, two entries
  19. InsOK equ   INSXY + 8         ; Okay row for insulin to be sent to
  20. TMP equ InsOK + 1             ; Temporary scratchpad
  21. InsGot equ  TMP + 8           ; How many insulin have been gotten already
  22. TitlPt equ  InsGot + 2        ; Pointer to the instructional text on the title
  23. InsKey equ  PLY + 2           ; How many insulin before the key?
  24. Score equ   InsKey + 1        ; Current score
  25. Lives equ   Score + 3         ; Current lives
  26. Level equ   Lives + 1         ; Current level number
  27. SugSP equ   Level + 1         ; Sugar troop speed, increases
  28. SavSP equ   SugSP + 2         ; Just me trying to save Stack Pointer
  29. Sdat equ    saveSScreen + 256 ; Data table for sugar troops
  30.     org userMem - 2
  31.     db  0BBh, 6Dh             ; mark this as an ASM program
  32. ; Mirage header
  33.     ret                       ; "Return" so Asm( doesn't crash
  34.                               ;  interpreting the icon as code
  35.     db  1                     ; This is a MirageOS program
  36.     db  00000000b, 00000000b  ; 15x15 icon
  37.     db  00001110b, 00000000b
  38.     db  00001011b, 11100000b
  39.     db  00001110b, 10100000b
  40.     db  00000000b, 00000000b
  41.     db  00000000b, 00000000b
  42.     db  00000111b, 11000000b
  43.     db  00001111b, 11100000b
  44.     db  00011011b, 10110000b
  45.     db  00011011b, 10110000b
  46.     db  00011111b, 11110000b
  47.     db  00011111b, 11110000b
  48.     db  00000100b, 01000000b
  49.     db  00000100b, 01000000b
  50.     db  00011100b, 01110000b
  51.     db  "Fast Eddie 83+", 0   ; Zero terminated description
  52. Start:
  53.     ld  (SavSP), sp
  54.     call    DoTitl            ; Display the title and let player read instructions
  55.     call    ClrScrn           ; Clear screen again
  56.     ld  hl, appData           ; Clear out the place we're storing variables
  57.     ld  bc, 256               ;   said place is 256 bytes big
  58.     B_CALL  _MemClear
  59.     ld  hl, saveSScreen       ; Clear most of SaveSScreen out
  60.     ld  bc, 768               ;   For playfield and Sugar Troop data
  61.     B_CALL  _MemClear
  62.     ld  hl, 40                ; Start with the sugar troops moving at a speed
  63.     ld  (SugSP), hl           ;   of 40
  64.     xor a                     ; Quick way to set A to zero
  65.     ld  (Level), a            ; First level
  66.     ld  a, 4                  ; Original game starts with 4 lives
  67.     ld  (Lives), a
  68.     call    NeLVL
  69.     ld  a, 5                  ; 5 insulin required for a key
  70.     ld  (InsKey), a
  71.     call    MainLoop
  72. ; Clean up
  73. Exit:                         ; Clean up
  74.     call    ClrScrn           ; Clear the screen
  75.     call    SafeCopy          ;
  76.     B_CALL  _HomeUp           ; Move the cursor back up
  77.     set 2, (iy + 0Dh)         ; The OS screws up when autoscroll is off
  78.     ret
  79.  
  80. ; Create level
  81. NeLVL:
  82. ; Update stats
  83.     ld  a, 0                  ; Reset player X position to zero
  84.     ld  (PLX + 1), a
  85.     ld  hl, (SugSP)           ; Add 10 to Sugar Troop speed
  86.     ld  bc, 10
  87.     add hl, bc
  88.     ld  (SugSP), hl
  89.     ld  a, (Level)            ; Next level, so increment level count
  90.     inc a
  91.     ld  (Level), a
  92.     ld  a, (InsKey)           ; One more key needed each level
  93.     inc a
  94.     ld  (InsKey), a
  95.     call    DoStatLvl         ; Show stats on what level it is, how many lives...
  96. ; Clear temp
  97.     ld  hl, appData           ; Clear the first half of AppData
  98.     ld  bc, 128
  99.     B_CALL  _MemClear
  100.     call    ClrScrn
  101.     ld  bc, 768               ; Also clear SaveSScreen because it stores the
  102.     ld  hl, saveSScreen       ;  playfield
  103.     B_CALL  _MemClear
  104. ; Generate level
  105.     ld  d, 0                  ; X position for floor
  106.     ld  e, 60                 ; Y position for floor
  107.     ld  b, 12                 ; Number of blocks to place
  108.     call    MkFL              ;   Make floor
  109.     ld  d, 0                  ; X position for floor
  110.     ld  e, 60 - 4 * 10        ; Y position for floor
  111.     ld  b, 12                 ; Number of blocks to place
  112.     call    MkFL              ;   Make floor
  113.     ld  e, 60 - 4 * 10        ; Only specify Y position
  114.     ld  b, 5                  ; 5 blocks tall
  115.     call    MkRLD             ;   Make two random ladders
  116.     ld  d, 0                  ; X position for floor
  117.     ld  e, 60 - 4 * 5         ; Y position for floor
  118.     ld  b, 12                 ; Number of blocks to place
  119.     call    MkFL              ;   Make floor
  120.     ld  e, 60 - 4 * 5         ; Only specify Y position
  121.     ld  b, 5                  ; Number of blocks to place
  122.     call    MkRLD             ;   Make two random ladders
  123. ; Place prizes
  124.     call    Rand              ; Random X pos
  125.     and 31
  126.     ld  b, a
  127.     ld  a, 90
  128.     sub b
  129.     ld  d, a                  ; load X position
  130.     ld  e, 60 - 4 * 4         ; preset Y position
  131.     ld  (INSXY), de           ; insulin slot 1
  132.  
  133.     call    Rand              ; Random X pos
  134.     and 31
  135.     add a, 5
  136.     ld  d, a                  ; load X position
  137.     ld  e, 60 - 4 * 9         ; preset Y position
  138.     ld  (INSXY + 2), de       ; insulin slot 2
  139.  
  140. ; Place Sneakers
  141.     call    Rand              ; Random X pos
  142.     and 63
  143.     add a, 16
  144.     ld  d, a
  145.     ld  e, 60 - 4 * 2         ; Fixed Y Pos
  146.     ld  (Sdat + 0 + 0), de    ; Store X,Y
  147.  
  148.     call    Rand              ; Random X pos
  149.     and 63
  150.     add a, 16
  151.     ld  d, a
  152.     ld  e, 60 - 4 * 7         ; Fixed Y pos
  153.     ld  (Sdat + 0 + 8), de    ; Store X,Y
  154.  
  155.     call    Rand              ; Random X pos
  156.     and 63
  157.     add a, 16
  158.     ld  d, a
  159.     ld  e, 12                 ; Fixed Y pos
  160.     ld  (Sdat + 0 + 16), de   ; Store X,Y
  161.  
  162. ; Available row
  163.     ld  a, 4                  ; First row is okay
  164.     ld  (InsOK), a
  165. ; Set speeds
  166.     ld  hl, (SugSP)           ; Take current speed
  167.     ld  (Sdat + 3 + 0), hl    ; Write to first enemy
  168.     ld  (Sdat + 3 + 16), hl   ; Write to third enemy
  169.     call    NegHL
  170.     ld  (Sdat + 3 + 8), hl    ; Write negative version to second enemy
  171.     ret
  172.  
  173. ; Player died
  174. Ganon:
  175.     xor a                     ; Reset X position
  176.     ld  (PLX + 1), a
  177.     ld  a, (Lives)            ; one less life
  178.     or  a
  179.     ret z                     ; all out of lives?
  180.     dec a
  181.     ld  (Lives), a
  182.     call    DoStatLvl         ; tell player how many lives are left
  183.     ret
  184.  
  185. NegHL:
  186.     xor a
  187.     sub l
  188.     ld  l, a
  189.     sbc a, a
  190.     sub h
  191.     ld  h, a
  192.     ret
  193.  
  194. NegDE:
  195.     xor a
  196.     sub e
  197.     ld  e, a
  198.     sbc a, a
  199.     sub d
  200.     ld  d, a
  201.     ret
  202.  
  203. ; Scroll down
  204. SCRD:
  205.     ld  hl, plotSScreen + 768 - 12
  206.     ld  de, plotSScreen + 768
  207.     ld  bc, 768 - 12
  208.     lddr
  209.     ret
  210.  
  211. ; Randomly set to other side of the field
  212. LDSi:
  213.     bit 0, c               ; Bit zero of random flag set?
  214.     ret z                  ; if not, return. We want a 1 in 2 chance
  215.     ld  ixl, a
  216.     ld  a, 11
  217.     sub ixl
  218.     ret
  219.  
  220. ; Make 2 random ladders
  221. MkRLD:
  222.     call    Rand           ; Other side maybe?
  223.     ld  c, a
  224.     call    Rand
  225.     and 7
  226.     call    LDSi
  227.     sla a                  ; Multiply by 8
  228.     sla a
  229.     sla a
  230.     ld  d, a
  231.     push    de
  232.     push    bc
  233.     call    MkLD2          ; Place one ladder
  234.     pop bc
  235.     pop de
  236.  
  237.     call    Rand
  238.     and 3
  239.     add a, 8
  240.  
  241.     call    LDSi
  242.     sla a                  ; Multiply by 8
  243.     sla a
  244.     sla a
  245.     ld  d, a
  246.     call    MkLD2          ; Place one ladder
  247.     ret
  248.  
  249. ; Make 1 ladder
  250. MkLD2:
  251. ; Mark in field bytes
  252.     push    de             ; Save DE
  253.     push    bc             ; Save BC
  254.     ld  ix, Pla + 8        ; Load platform graphic
  255.     ld  b, 4               ; 4 pixels high
  256.     call    Spr8b          ; Cancel platform graphic out with XOR
  257.     pop bc
  258.     pop de
  259. MkLD:
  260.     call    bmDE           ; Find block index
  261.     ld  a, 4               ; Block type 4 is ladder
  262.     ld  (hl), a            ; Put it in the index
  263.     push    bc
  264.     push    de
  265. ; Draw
  266.     ld  ix, Pla + 16       ; Load ladder graphic
  267.     ld  b, 4
  268.     call    Spr8b          ; XOR draw it
  269.     pop de
  270.     pop bc
  271.     ld  a, e               ; Move down 4 pixels
  272.     add a, 4
  273.     ld  e, a
  274.     djnz    MkLD           ; Make another ladder block
  275.     ret
  276.  
  277. MkFL:                      ; Make floor
  278.     call    bmDE           ; Calculate block index
  279.     ld  a, 3               ; Block type 3 is floor
  280.     ld  (hl), a
  281.     push    bc
  282.     push    de
  283.     ld  ix, Pla + 8
  284.     ld  b, 4
  285.     call    Spr8b          ;XOR draw it
  286.     pop de
  287.     pop bc
  288.     ld  a, 8               ; Move right 8 pixels
  289.     add a, d
  290.     ld  d, a
  291.     djnz    MkFL           ; Make more floor blocks
  292.     ret
  293.  
  294. ; D(X) E(Y) - HL(Ptr)
  295. bmDE:
  296.     push    de
  297.     ld  a, d
  298.     add a, 4
  299.     and 01111000b
  300.     sla a
  301.     srl e
  302.     srl e
  303.     or  e
  304.     ld  e, a
  305.     ld  hl, saveSScreen
  306.     ld  d, 0
  307.     add hl, de
  308.     ld  a, (hl)
  309.     pop de
  310.     ret
  311.  
  312. ; Ion random
  313. Rand:
  314.     push    hl
  315.     push    de
  316.     ld  hl, (seed1)
  317.     ld  a, r
  318.     ld  d, a
  319.     ld  e, (hl)
  320.     add hl, de
  321.     ld  a, l
  322.     xor h
  323.     ld  (seed1), hl
  324.     pop de
  325.     pop hl
  326.     ret
  327.  
  328. ;#SECTION "Loop", CODE
  329.  
  330. ; Game logic here
  331. MainLoop:
  332.     ld  a, (FCA)           ; Update frame counter
  333.     inc a
  334.     ld  (FCA), a
  335.     call    ChL            ; On ladder?
  336.     call    CoB            ; Touching block?
  337.     call    KIL            ; Kill ladder movement if needed
  338.     call    VML            ;Move vertically for ladder if needed
  339.     call    Fal            ;Try to fall
  340.  
  341.     call    DoSTs            ; Draw+Move sugar troops
  342.     call    DrP              ; Draw player
  343.     call    DoIN             ; Draw insulin
  344.     call    DrKey            ; Draw key if needed
  345.     call    SafeCopy           ; Copy PlotSScreen to the LCD display
  346.     call    DrKey            ; Draw key again to erase
  347.     call    DrIN             ; Draw insulin again to erase
  348.     call    DrP              ; Draw player again to erase
  349.     call    DrSTs            ; Draw sugar troops again to erase
  350.  
  351.     ld  b, 0FEh            ; Read cursor keys!
  352.     call    ReadGrp
  353.     ld  c, a               ; 'A' gets altered a lot. Let's put it in C!
  354.     bit 1, c               ; Left key
  355.     call    z, MovL
  356.     bit 2, c               ; Right key
  357.     call    z, MovR
  358.  
  359.     ld  b, 0FDh            ; Key group with Clear as part of it
  360.     call    ReadGrp
  361.     cp  0BFh               ; ... was Clear pressed?
  362.     ret z                  ; Exit the game if so!
  363.  
  364. ; Game over
  365.     ld  a, (Lives)         ; Okay, so are we out of lives?
  366.     or  a                  ; Quick way to check against zero
  367.     ret z                  ; Exit if out of lives
  368.  
  369.     jp  MainLoop           ; Othewise, KEEP GOING
  370.  
  371. ; check stop ladder
  372. KIL:
  373.     ld  a, (LAD)           ; Check ladder status
  374.     or  a                  ;   if it's zero, this check is not needed
  375.     ret z                  ;   exit
  376.     call    bmDE           ; Are we still on a ladder?
  377.     cp  4                  ; ( 4 is the ladder code )
  378.     ret z                  ; Return if we are still on a ladder
  379.     ld  a, 0               ; Otherwise, kill ladder state
  380.     ld  (LAD), a
  381.     ret
  382.  
  383. ; Do ladder moving
  384. VML:
  385.     ld  a, (LAD)           ; Are we moving on a ladder?
  386.     or  a                  ; Quick way to check against zero
  387.     ret z
  388.     ld  b, a               ; Move ladder speed to B so we can do this:
  389.     ld  a, (PLY + 1)       ; Offset Y position by ladder speed
  390.     add a, b               ;
  391.     ld  (PLY + 1), a       ;
  392.     ret
  393.  
  394. ; Climb up
  395. ClU:
  396.     ld  a, (PLX + 1)       ; Snap to the ladder so it doesn't look funky
  397.     add a, 4
  398.     and 11111000b
  399.     ld  (PLX + 1), a
  400.  
  401.     ld  a, -1              ; Upwards
  402.     ld  (LAD), a
  403.     ret
  404.  
  405. ; Climb down
  406. ClD:
  407.     ld  a, (PLX + 1)       ; Snap to the ladder so it doesn't look funky
  408.     add a, 4
  409.     and 11111000b
  410.     ld  (PLX + 1), a
  411.  
  412.     ld  a, 1               ; Downwards
  413.     ld  (LAD), a
  414.     ret
  415.  
  416. ; Check if on ladder
  417. ChL:
  418.     ld  a, (PLX + 1)       ; Load DE for bmDE
  419.     ld  d, a
  420.     ld  a, (PLY + 1)
  421.     ld  e, a
  422.  
  423.     call    bmDE           ; Calculate index and read
  424.     cp  4                  ; Ladder object?
  425.     jp  nz, ChL2           ; Okay, can we climb down?
  426.  
  427.     ld  b, 0FEh            ; Read cursor keys
  428.     call    ReadGrp
  429.     bit 3, a               ; Check for up
  430.     jp  z, ClU             ; Climb up
  431.  
  432. ChL2:                      ; Check four tiles BELOW player
  433.     ld  a, (PLX + 1)       ; Load DE for bmDE ( plus four below )
  434.     ld  d, a
  435.     ld  a, (PLY + 1)
  436.     add a, 4
  437.     ld  e, a
  438.     call    bmDE
  439.  
  440.     cp  4                  ; is THAT a ladder?
  441.     ret nz                 ; NO
  442.  
  443.     ld  b, 0FEh            ; Read cursor keys
  444.     call    ReadGrp
  445.     bit 0, a               ; Pressing down?
  446.     jp  z, ClD             ; Climb down!
  447.     ret
  448.  
  449. ; Check touching block
  450. CoB:
  451.     ld  a, (LAD)           ; Ignore if on a ladder, moving
  452.     or  a                  ; Quick way to check against zero
  453.     ret nz
  454.  
  455.     ld  a, (VLY + 1)       ; Ignore if moving upwards
  456.     bit 7, a
  457.     ret nz
  458.  
  459.     ld  a, (PLX + 1)       ; Load DE for bmDE
  460.     ld  d, a
  461.     ld  a, (PLY + 1)
  462.     add a, 4
  463.     ld  e, a
  464.     call    bmDE
  465.  
  466.     cp  0                  ; Empty space?
  467.     call    nz, Sol        ; if not, stop falling
  468.     ret
  469.  
  470. ; Check solid
  471. Sol:
  472.     ld  a, 0
  473.     ld  (PLY), a           ; NO partial Y positioning
  474.     ld  (VLY), a           ; NO partial vertical movement
  475.     ld  (VLY + 1), a       ; NO complete vertical movement
  476.  
  477.     ld  a, (PLY + 1)
  478.     and 01111100b          ; SNAP vertically
  479.     ld  (PLY + 1), a
  480.  
  481.     ; If we're on solid ground, we can jump, so check here
  482.     ld  b, 0BFh            ; Button group with 2nd
  483.     call    ReadGrp        ; read
  484.     cp  0DFh               ; is 2nd pressed?
  485.     call    z, DoJmp
  486.     ret
  487.  
  488. ; Vert velocity
  489. DoJmp:
  490.     ld  de, -150
  491.     ld  (VLY), de
  492.     ret
  493.  
  494. ; Player move left
  495. MovL:
  496.     ld  a, (FCA)           ; Can only move every other frame
  497.     bit 0, a
  498.     ret z
  499.  
  500.     ld  a, (PLX + 1)
  501.     dec a
  502.     cp  -1                 ; Can't move off the screen
  503.     ret z
  504.     ld  (PLX + 1), a
  505.     ret
  506.  
  507. ; Player move right
  508. MovR:
  509.     ld  a, (FCA)           ; Can only move every other frame
  510.     bit 0, a
  511.     ret z
  512.     ld  a, (PLX + 1)
  513.     inc a
  514.     cp  97 - 8             ; Can't move off the screen
  515.     ret z
  516.     ld  (PLX + 1), a
  517.     ret
  518.  
  519. ; Draw player
  520. DrP:
  521.     ld  a, (PLX + 1)       ; Load DE with player position for Spr8b
  522.     ld  d, a
  523.     ld  a, (PLY + 1)
  524.     sub 4
  525.     ld  e, a
  526.  
  527.     ld  ix, PLS            ; Player sprite
  528.     ld  b, 8               ; 8 pixels tall
  529.     call    Spr8b          ; XOR draw
  530.     ret
  531.  
  532. ; Fall due to gravity
  533. Fal:
  534.     ld  a, (LAD)           ; DON'T fall if moving on a ladder
  535.     or  a                  ; Quick way to check against zero
  536.     ret nz                 ;
  537.  
  538.     ld  bc, 4              ; Gravity increment
  539.     ld  de, (PLY)
  540.  
  541.     ld  hl, (VLY)          ; Increase the amount of gravity
  542.     add hl, bc
  543.     ld  (VLY), hl
  544.  
  545.     add hl, de             ; Increase player Y by amount of gravity
  546.     ld  (PLY), hl
  547.     ret
  548.  
  549. ;#SECTION "Data", DATA
  550.  
  551. Pla:                       ; Block graphics
  552.     db  0, 0, 0, 0
  553.     db  255, 129, 129, 255 ; UNUSED
  554.     db  255, 213, 171, 255 ; UNUSED
  555.     db  255, 143, 241, 255 ; Platform
  556.     db  195, 255, 255, 195 ; Ladder
  557. KeyS:
  558.     db  00000000b          ; Key graphic
  559.     db  01000000b
  560.     db  10111110b
  561.     db  01001010b
  562. SugS:
  563.     db  00111100b          ; Sugar Troop graphic
  564.     db  01111110b
  565.     db  11011011b
  566.     db  11011011b
  567.     db  11111111b
  568.     db  00100100b
  569.     db  00100110b
  570.     db  01100000b
  571.  
  572.     db  00111100b
  573.     db  01111110b
  574.     db  11011011b
  575.     db  11011011b
  576.     db  11111111b
  577.     db  00100100b
  578.     db  01100100
  579.     db  00000110b
  580.  
  581. InsS:                      ; Insulin graphic
  582.     db  10101010b
  583.     db  01010101b
  584.     db  10101010b
  585.     db  01010101b
  586.  
  587.     db  01010101b
  588.     db  10101010b
  589.     db  01010101b
  590.     db  10101010b
  591.  
  592. PLS:                       ; Player sprite
  593.     db  00111100b
  594.     db  01000010b
  595.     db  10100101b
  596.     db  10100101b
  597.     db  10000001b
  598.     db  10011001b
  599.     db  01000010b
  600.     db  00111100b
  601. Titl:                      ; Title name
  602.     db  " FastEddie 83+  ", 0
  603. Auth:                      ; Author (ME)
  604.     db  "Written by Wahovipab, 2010", 0
  605. CLSign:                    ; ... copyleft?
  606.     db  01111100b
  607.     db  10110010b
  608.     db  10001010b
  609.     db  10001010b
  610.     db  10110010b
  611.     db  01111100b
  612. Stry:                      ; WOW STORY TIME
  613.     db  "Help Fast Eddie "
  614.     db  " collect enough "
  615.     db  " prizes to reach"
  616.     db  " the next level ", 0
  617. Stry2:                     ; PAGE TWO OF STORY
  618.     db  "After enough    "
  619.     db  " prizes, a key  "
  620.     db  " appears. Grab  "
  621.     db  " it to continue ", 0
  622. Ctrls:                     ; PAGE THREE OF STORY
  623.     db  "2nd:   Jump     "
  624.     db  "\xcf/\x05:   Walk     "
  625.     db  "\x1e/\x1f:   Climb    "
  626.     db  "Clear: Exit     ", 0
  627. ScoreT:
  628.     db  "Score: ", 0
  629. LevelT:
  630.     db  "Level: ", 0
  631. LivesT:
  632.     db  "Lives: ", 0
  633. Pressakey:
  634.     db  "Press a key...", 0
  635. InstrTxt:
  636.     db  "\xcf/\x05: Turn Page            "
  637.     db  "2nd: Start      ", 0
  638. InstrTbl:                  ; Table of pointers to story pages
  639.     word    0, Ctrls, Stry, Stry2, 0
  640. InstrTen:
  641. ;#SECTION "Sugar", CODE
  642.  
  643. DoSTr:                     ; Do one sugar troop
  644.     push    ix
  645.     push    de
  646.     push    hl
  647.     ld  d, (ix + 1)
  648.     ld  e, (ix + 0)
  649.     call    ColS           ; Touching sugar troop? If so, die
  650.     pop hl
  651.     pop de
  652.     pop ix
  653.  
  654.     ld  h, (ix + 1)        ; Load horizontal position
  655.     ld  l, (ix + 2)
  656.  
  657.     ld  d, (ix + 4)        ; Load speed
  658.     ld  e, (ix + 3)
  659.  
  660.     add hl, de             ; Move sideways by speed amount
  661.     ld  (ix + 1), h
  662.     ld  (ix + 2), l
  663.  
  664.     ld  d, (ix + 4)        ; load again for no reason
  665.     ld  e, (ix + 3)        ; kinda illegal
  666.  
  667.     ld  a, (ix + 1)        ; very illegal please don't sue me
  668.  
  669.     or  a                  ; Quick way to check against zero
  670.     call    z, NegDE       ; reverse direction if touching left edge
  671.  
  672.     ld  a, (ix + 1)        ; Reloading why?
  673.     cp  96 - 8
  674.     call    z, NegDE       ; reverse direction if touching right edge
  675.  
  676.     ld  (ix + 4), d        ; WRITE BACK
  677.     ld  (ix + 3), e
  678. DrSTr:                     ; darling we don't simply draw the sugar troop
  679.     ld  b, 8               ; 8 height
  680.     ld  d, (ix + 1)        ; X position
  681.     ld  e, (ix + 0)        ; Y position
  682.     push    ix             ; preserve IX
  683.  
  684.     ld  ix, SugS           ; Load sugar troop image
  685.     ld  a, (FCA)           ;
  686.     bit 3, a
  687.     call    z, FlpS        ; Animate between two frames
  688.     call    Spr8b          ; draw
  689.  
  690.     pop ix                 ; Next sugar troop!
  691.     ld  bc, 8              ; 'nother register
  692.     add ix, bc
  693.     ret
  694.  
  695. DrKey:                     ; Draw key
  696.     ld  a, (InsGot)        ; Do we even have enough insulin for a key to appear
  697.     ld  b, a               ; move
  698.     ld  a, (InsKey)
  699.     cp  b                  ; Keys Gotten >= Keys Needed
  700.     ret nc                 ; No?
  701.  
  702.     ld  hl, (Sdat + 0 + 16) ; load sugar troop Y
  703.     ld  de, -8             ; minus 8
  704.     add hl, de
  705.  
  706.     push    hl             ; Save HL
  707.     push    hl             ; Make another copy for DE
  708.     pop de                 ; Copy to DE
  709.     call    Col8b          ; Touching player?
  710.     jp  c, NNeLVL          ; NEW LEVEL BECAUSE KEY IS TOUCHED
  711.     pop de                 ; ... huh? OH! For Spr8b
  712.  
  713.     ld  ix, KeyS           ; Key sprite
  714.     ld  b, 4               ; 4 tall
  715.     call    Spr8b          ; XOR draw it
  716.     ret
  717.  
  718. NNeLVL:
  719.     pop hl                 ; die
  720.     pop hl                 ; die
  721.     call    NeLVL          ; New Level
  722.     jp  MainLoop           ; Return to main loop
  723.     ret
  724.  
  725. DoSTs:                     ; Do all 3 sugar troops
  726.     ld  ix, Sdat
  727.     call    DoSTr
  728.     call    DoSTr
  729.     call    DoSTr
  730.     ret
  731.  
  732. DrSTs:                     ; Draw all 3 sugar troops
  733.     ld  ix, Sdat
  734.     call    DrSTr
  735.     call    DrSTr
  736.     call    DrSTr
  737.     ret
  738.  
  739. FlpS:                      ; IX += B
  740.     push    bc             ; Save BC
  741.     ld  c, b
  742.     ld  b, 0
  743.     add ix, bc
  744.     pop bc                 ; Restore BC
  745.     ret
  746.  
  747. ;#SECTION "Insulin", CODE
  748.  
  749. DoIN:                     ; Do both insulins
  750.     ld  a, (FCA)          ;   only move insulin 1 in 8 frames
  751.     and 7
  752.     jp  nz, DrIN
  753.  
  754.     ld  a, (INSXY + 1)    ; MOVE FORWARD
  755.     inc a
  756.     ld  (INSXY + 1), a
  757.  
  758.     ld  a, (INSXY + 3)    ; MOVE BACKWARD
  759.     dec a
  760.     ld  (INSXY + 3), a
  761.  
  762.     ld  ix, INSXY + 2     ; Move if on the edge
  763.     ld  a, (ix + 1)
  764.     or  a
  765.     call    z, NeIP       ; new position
  766.  
  767.     ld  ix, INSXY         ; Move if on the edge
  768.     ld  a, (ix + 1)
  769.     cp  96 - 8
  770.     call    z, NeIP       ; new position
  771.  
  772.     ld  ix, INSXY          ; React to getting the insulin
  773.     ld  de, (INSXY)
  774.     call    Col8b
  775.     call    c, GotI
  776.  
  777.     ld  ix, INSXY + 2      ; React to getting the insulin
  778.     ld  de, (INSXY + 2)
  779.     call    Col8b
  780.     call    c, GotI
  781. DrIN:
  782.     ld  a, (INSXY + 4)     ; Insulin 1 ENABLED?
  783.     or  a                  ; Check if not zero very quickly
  784.     jp  nz, DrInS          ; skip first insulin
  785.  
  786.     ld  ix, InsS           ; insulin graphic
  787.     ld  de, (INSXY)
  788.     ld  b, 4
  789.     ld  a, (FCA)           ; framecounter
  790.     bit 0, a               ; every other frame in framecounter results
  791.     call    z, FlpS        ; in other frame for GRAYSCALE EFFECT
  792.     call    Spr8b          ; draw
  793. DrInS:
  794.     ld  a, (INSXY + 5)     ; Insulin 2 ENABLED?
  795.     or  a                  ; Check if not zero very quickly
  796.     ret nz                 ; skip rest
  797.  
  798.     ld  ix, InsS           ; insulin graphic
  799.     ld  b, 4
  800.     ld  a, (FCA)           ; framecounter
  801.     bit 0, a               ; every other frame in framecounter results
  802.     call    z, FlpS        ; in other frame for GRAYSCALE EFFECT
  803.     ld  de, (INSXY + 2)    ; load XY for drawing
  804.     call    Spr8b          ; draw
  805.     ret
  806.  
  807. GotI:                      ; Got one insulin
  808.  
  809.     ld  de, 15             ; add 15 to score
  810.     ld  hl, (Score)
  811.     add hl, de
  812.     ld  (Score), hl
  813.  
  814.     ld  a, (InsGot)        ; Mark one more insulin gotten
  815.     inc a
  816.     ld  (InsGot), a
  817.  
  818.     push    ix             ; why am I smashing my hand with this hammer
  819.     ld  d, a
  820.     ld  e, 0
  821.     call    GetPixel       ; Mark in the meter of how many insulins gotten
  822.     or  (hl)               ; OR the dot in
  823.     ld  (hl), a            ; update
  824.     pop ix
  825.  
  826.     call    NeIP           ; New row and position
  827.     ret
  828.  
  829. PCom:                      ; load player XY into HL
  830.     ld  a, (PLX + 1)
  831.     ld  h, a
  832.     ld  a, (PLY + 1)
  833.     ld  l, a
  834.     ret
  835.  
  836. NeIP:                      ; New position and row
  837.  
  838.     ld  b, (ix + 0)        ; take the new avaliable row
  839.     ld  a, (InsOK)         ; fetch good Y
  840.     ld  (ix + 0), a        ; update Y
  841.     ld  a, b               ; restore bad Y
  842.     ld  (InsOK), a         ; set it to old row
  843.  
  844.     call    Rand           ; Make random X position
  845.     and 63
  846.     add a, 16
  847.     ld  (ix + 1), a        ; Load in
  848.  
  849.     call    Rand           ; 50% chance of other side
  850.     bit 0, a
  851.     ret z
  852.  
  853.     ld  a, 95 - 8          ; Other side...
  854.     sub (ix + 1)
  855.     ld  (ix + 1), a        ; Update
  856.     ret
  857.  
  858. DecA:                      ; Useless
  859.     dec a
  860.     ret
  861.  
  862. ;#SECTION "Utility", CODE
  863.  
  864. ColS:                      ; Collide with sugar troop?
  865.     ld  a, (LAD)
  866.     or  a
  867.     ret nz
  868.  
  869.     ld  a, (PLX + 1)       ; Load my X
  870.     add a, 4
  871.     ld  h, a
  872.  
  873.     ld  a, (PLY + 1)       ; Load my Y
  874.     add a, 4
  875.     ld  l, a
  876.  
  877.     ld  a, (ix + 1)        ; Load sugar X
  878.     add a, 4
  879.     ld  d, a
  880.  
  881.     ld  a, (ix + 0)        ; Load sugar Y
  882.     add a, 4
  883.     ld  e, a
  884.  
  885.     call    ColS2          ; COLLIDE?
  886.     ex  de, hl             ; okay maybe not
  887.     call    ColS2          ; COLLIDE???
  888.     ret
  889.  
  890. ColS2:
  891.     ld  a, h               ; not outside
  892.     cp  d
  893.     ret c
  894.  
  895.     ld  a, l               ; not outside
  896.     cp  e
  897.     ret c
  898.  
  899.     ld  a, d               ; not outside
  900.     add a, 8
  901.     cp  h
  902.     ret c
  903.  
  904.     ld  a, e               ; not outside
  905.     add a, 4
  906.     cp  l
  907.     ret c
  908.  
  909.     pop af                 ; garbage pop
  910.     jp  Ganon              ; you must die
  911.  
  912. ChCT:
  913.     ld  a, h
  914.     cp  d
  915.     ret c
  916.  
  917.     ld  a, l
  918.     cp  e
  919.     ret c
  920.  
  921.     ld  a, d
  922.     add a, 7
  923.     cp  h
  924.     ret c
  925.  
  926.     ld  a, e
  927.     add a, 7
  928.     cp  l
  929.     ret c
  930.  
  931.     pop af                 ; Garbage pop
  932.     pop de
  933.     pop hl
  934.     scf                    ; collision has occured
  935.     ret
  936.  
  937. Col8b:                     ; Collision?
  938.     push    hl
  939.     push    de
  940.     dec d
  941.     dec d
  942.     dec d
  943.     dec d
  944.     ld  a, (PLX + 1)       ; load player XY into HL
  945.     ld  h, a
  946.     ld  a, (PLY + 1)
  947.     ld  l, a
  948.     call    ChCT           ; HL inside DE
  949.     ex  de, hl
  950.     call    ChCT           ; DE inside HL
  951.     pop de
  952.     pop hl
  953.     ccf                    ; I used to think CCF was "clear carry flag"
  954.     ret
  955.  
  956. ;#SECTION "Menu", CODE
  957.  
  958. DrTitl:                    ; draw title at the top
  959.     B_CALL  _HomeUp
  960.     set textInverse, (iy + textFlags)
  961.     ld  hl, Titl
  962.     B_CALL  _PutS
  963.     res textInverse, (iy + textFlags)
  964.     ret
  965.  
  966. DoStatLvl:                 ; lives and level
  967.     ld  hl, plotSScreen    ; COPY SCREEN TO BACK IT UP
  968.     ld  de, appBackUpScreen
  969.     ld  bc, 768
  970.     ldir
  971.     call    ClrScrn        ; Clear screen
  972.     call    SafeCopy       ; copy to screen
  973.     call    DrTitl         ; draw title
  974.  
  975.     ld  hl, LevelT         ; display level
  976.     B_CALL  _PutS
  977.     ld  a, (Level)
  978.     call    NDspA
  979.  
  980.     ld  hl, LivesT         ; display lives
  981.     B_CALL  _PutS
  982.     ld  a, (Lives)
  983.     call    NDspA
  984.  
  985.     ld  hl, ScoreT         ; display score
  986.     B_CALL  _PutS
  987.     ld  hl, (Score)
  988.     call    NDspHL
  989.  
  990.     ld  a, 7
  991.     ld  (curRow), a
  992.     ld  hl, Pressakey
  993.     B_CALL  _PutS
  994.  
  995.     call    AnyKey         ; wait for key
  996.     ld  hl, appBackUpScreen
  997.     ld  de, plotSScreen    ; copy back
  998.     ld  bc, 768
  999.     ldir
  1000.     ret
  1001.  
  1002. NDspA:                     ; Display A, newline
  1003.     ld  h, 0
  1004.     ld  l, a
  1005. NDspHL:                    ; Display HL, newline
  1006.     B_CALL  _DispHL
  1007.     B_CALL  _NewLine
  1008.     ret
  1009.  
  1010. DoTitl:                    ; Draw title
  1011.     res 2, (iy + 0Dh)
  1012.     res 5, (iy + 0)
  1013.     ld  hl, InstrTbl + 2
  1014.     ld  (TitlPt), hl
  1015.     call    ClrScrn
  1016.     call    DrTitl
  1017.     ; put instructions for reading instructions
  1018.     ld  a, 5 * 8 + 6
  1019.     ld  (penRow), a
  1020.     xor a
  1021.     ld  (penCol), a
  1022.     ld  hl, InstrTxt
  1023.     B_CALL  _VPutS
  1024.     ; credit myself
  1025.     ld  a, 7 * 8
  1026.     ld  (penRow), a
  1027.     xor a
  1028.     ld  (penCol), a
  1029.     ld  hl, Auth
  1030.     B_CALL  _VPutS
  1031.  
  1032.     res textInverse, (iy + textFlags)
  1033.     call    TitlCtrl
  1034.     ret
  1035.  
  1036. TitlCtrl:
  1037.     ld  a, 1
  1038.     ld  (curRow), a
  1039.     xor a
  1040.     ld  (curCol), a
  1041.     ld  hl, (TitlPt)
  1042.     B_CALL  _LdHLind
  1043.     B_CALL  _PutS
  1044. .gk:
  1045.     B_CALL  _GetCSC
  1046.     or  a
  1047.     jp  z, .gk
  1048.     cp  skLeft
  1049.     jp  z, .mL
  1050.     cp  skRight
  1051.     jp  z, .mR
  1052.     cp  skClear
  1053.     jp  z, .Exit2
  1054.     ret
  1055.  
  1056. .Exit2:
  1057.     pop hl
  1058.     pop hl
  1059.     ret
  1060.  
  1061. .mL:
  1062.     ld  hl, (TitlPt)
  1063.     dec hl
  1064.     dec hl
  1065.     ld  (TitlPt), hl
  1066.     B_CALL  _LdHLind       ; get current pointed data
  1067.     ld  a, h
  1068.     or  a                  ; going to inalid page?
  1069.     jp  nz, TitlCtrl
  1070.  
  1071.     ld  hl, InstrTbl + 2
  1072.     ld  (TitlPt), hl
  1073.     jp  TitlCtrl
  1074.  
  1075. .mR:
  1076.     ld  hl, (TitlPt)
  1077.     inc hl
  1078.     inc hl
  1079.     ld  (TitlPt), hl
  1080.     B_CALL  _LdHLind       ; get current pointed data
  1081.     ld  a, h
  1082.     or  a                  ; going to invalid page?
  1083.     jp  nz, TitlCtrl
  1084.  
  1085.     ld  hl, InstrTen - 4
  1086.     ld  (TitlPt), hl
  1087.     jp  TitlCtrl
  1088.  
  1089. AnyKey:                    ; wait for any key
  1090.     ld  b, 0FEh            ; but wait for cursor keys to be release first
  1091.     call    ReadGrp
  1092.     or  a
  1093.     cp  0FFh
  1094.     jp  nz, AnyKey
  1095. .L:                        ; wait until a key is pressed
  1096.     B_CALL  _GetCSC
  1097.     or  a
  1098.     jp  z, .L
  1099.     ret
  1100.  
  1101. Nput:                      ; put, also newline
  1102.     B_CALL  _PutS
  1103.     B_CALL  _NewLine
  1104.     ret
  1105.  
  1106. ;#IMPORT "LCDLIB"
  1107. ; doesn't define much. I can include it if you like
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement