Geekboy

Untitled

Mar 15th, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Renders the text animation and text box to screen and handles text reading stuffs
  2. ;inputs: hl=text_pointer
  3. Text_Output:
  4.     call tobackbuff
  5. ___TORevert:
  6.     push hl
  7.         rectangle(0,43,95,63,0)
  8.         box(0,43,95,63,1)
  9.         ld a,44
  10.         ld (penRow),a
  11.         ld a,2
  12.         ld (penCol),a
  13.     pop hl
  14. ___TOloop:
  15.     call IsKey
  16.         call z, Slowdown
  17.     ld a, (hl)
  18.     inc hl
  19.     cp '\n'
  20.         jr z, ___TOWrapLine
  21.     cp '\r'
  22.         jr z,___TOPage
  23.     or a
  24.         jr z, __TOEnd
  25.     b_call _VPutMap
  26.     call IsKey
  27.         call z,Fastcopys
  28.     ld a,(penCol)
  29.     cp 92
  30.         jr nc,___TOWrapLine
  31.     cp 86
  32.         jr nc,+_
  33.     jr ___TOloop
  34. _   ld a,(penRow)
  35.     push af
  36.     cp 51
  37.         jr nc,+_
  38.     pop af
  39.     jr ___TOloop
  40. ___TOWrapLine:
  41.     push af
  42.         ld a,2
  43.         ld (penCol),a
  44.         ld a,(penRow)
  45.         add a, 6
  46.         cp 57
  47.             jr nc,_
  48.         ld (penRow),a
  49.     pop af
  50.     jr ___TOloop
  51. ___TOPage:
  52.     push af
  53. _:
  54.         push hl
  55.             sprite(87,55,8,parse_pause_sprite)
  56.             lcdupdate
  57.             call _
  58.             rectangle(0,43,95,63,0)
  59.             box(0,43,95,63,1)
  60.         pop hl
  61.     pop af
  62.     jp ___TORevert
  63. __TOEnd:
  64.     push hl
  65.         sprite(87,55,8,parse_pause_sprite)
  66.         lcdupdate
  67.         call frombackbuff
  68.         call _
  69.         lcdupdate
  70.     pop hl
  71.     ret
  72. _   ;debug
  73.     call FlushKey
  74.     call Pause
  75.     ret
  76.    
  77. ;slows down stuff
  78. Slowdown:
  79.     ld c,$0F
  80. _       ld b,$FF
  81. _           push bc
  82.             pop bc
  83.             djnz -_
  84.         dec c
  85.         ld a,c
  86.         or a
  87.             jr nz,--_
  88.     ret
  89. ;saves the savefile
  90. file_save:
  91.     call tobackbuff ;store the screen to the backbuffer
  92.     homeup  ;position penCol/Row at top left hand side of the screen
  93.     ld hl,save_appvar_name  ;load the appvar savename into hl
  94.     rst 20h ;no idea
  95.     b_call _chkfindsym  ;check if it exists
  96.         jr nc,++_   ;if it exists jump to archive check
  97.     ld hl,DefaultSettingsEnd-DefaultSettings    ;load size into hl
  98.     b_call _createappvar    ;create the appvar
  99. _   inc de  ;increase past
  100.     inc de  ;the size bytes
  101.     ld hl,SaveStart ;load the data location to save from
  102.     ld bc,DefaultSettingsEnd-DefaultSettings    ;and the size
  103.     ldir    ;copy data
  104.     wrappedtext(saved_text) ;display save message
  105.     lcdupdate   ;update the screen
  106.     call Pause  ;pause till keypress
  107.     call frombackbuff   ;restore screen from backbuffer
  108.     ret
  109. _   xor a   ;archive check set a to 0
  110.     cp b    ;if b is zero (unarchived)
  111.         jr z,--_    ;go to save
  112.     ld hl,save_appvar_name  ;otherwise store the name to hl
  113.     rst 20h ;no clue why this is here
  114.     b_call _Arc_Unarc   ;unarchive the appvar
  115.     jr --;go to save
  116.  
  117. ;displays the name menu used to change the characters name
  118. name_menu:
  119.     call tobackbuff
  120.     xor a   ;set a 0
  121.     ld (_cursor),a
  122.     rectangle(5,4,75,61,0) \ rectangle(4,5,76,60,0)
  123.     largeSprite(4,4,9,57,MenuImg)
  124.     ld hl,(6*256)+6 ;set x
  125.     ld (penCol),hl  ;and y loc
  126.     wrappedtext(NameMenuTitle)
  127.     ld a,6
  128.     ld (penCol),a
  129.     ld a,28
  130.     ld (penRow),a
  131.     wrappedtext(NameMenuItems)
  132. name_menu_loop:
  133.         call name_menu_disp
  134.         b_call _getCSC
  135.         cp skRight
  136.             jr z,name_menu_cr
  137.         cp skLeft
  138.             jr z,name_menu_cl
  139.         cp skUp
  140.             jr z,name_menu_cu
  141.         cp skDown
  142.             jr z,name_menu_cd
  143.         cp skMode
  144.             jr z,_
  145.         cp skClear
  146.             jr z,_
  147.         cp skGraph
  148.             jr nz,name_menu_loop
  149. _   xor a   ;set a 0
  150.     ld (_cursor),a
  151.     call frombackbuff
  152.     ret
  153. name_menu_disp:
  154.     rectangle(6,16,74,25,0) ;display name string and cursor
  155.     ld a,19
  156.     ld (penRow),a
  157.     ld a,(_cursor)  ;get cursor position
  158.     ld c,a
  159.     add a,a
  160.     add a,c
  161.     add a,a ;mult by 6
  162. _   add a,7 ;add standard 7
  163.     ld (penCol),a   ;store position
  164.     ld a,'_'
  165.     b_call _VPutMap
  166.     ld a,16
  167.     ld (penRow),a
  168.     ld a,7
  169.     ld (penCol),a
  170.     monospacetext(Name)
  171.     lcdupdate
  172.     ret
  173. name_menu_cr:
  174.     ld a,(_cursor)
  175.     cp 10
  176.         jr z,name_menu_loop
  177.     inc a
  178.     ld (_cursor),a
  179.     jr name_menu_loop
  180. name_menu_cl:
  181.     ld a,(_cursor)
  182.     or a
  183.         jr z,name_menu_loop
  184.     dec a
  185.     ld (_cursor),a
  186.     jr name_menu_loop
  187. name_menu_cu:
  188.     ld hl,Name
  189.     ld a,(_cursor)
  190.     ld e,a
  191.     ld d,0
  192.     add hl,de
  193.     ld a,(hl)
  194.     cp 122
  195.         jp z,name_menu_loop
  196.     inc a
  197.     ld (hl),a
  198.     jp name_menu_loop
  199. name_menu_cd:
  200.     ld hl,Name
  201.     ld a,(_cursor)
  202.     ld e,a
  203.     ld d,0
  204.     add hl,de
  205.     ld a,(hl)
  206.     cp 32
  207.         jp z,name_menu_loop
  208.     dec a
  209.     ld (hl),a
  210.     jp name_menu_loop
  211. ;32-122 is (space)-z
  212.  
  213. ;displays the contrast menu used to change the contrast
  214. contrast_menu:
  215.     call tobackbuff
  216.     rectangle(5,4,75,61,0) \ rectangle(4,5,76,60,0)
  217.     largeSprite(4,4,9,57,MenuImg)
  218.     ld a,6                  ;set
  219.     ld (penCol),a           ;x and
  220.     ld (penRow),a           ;y loc
  221.     wrappedtext(ContrastMenuTitle)
  222.     call ++_
  223.     ld a,16
  224.     ld (penRow),a
  225.     wrappedtext(ContrastMenuItem0)
  226.     ld a,(currentContrast)
  227.     call VDispA
  228.     call ++_
  229.     ld a,22
  230.     ld (penRow),a
  231.     wrappedtext(ContrastMenuItem1)
  232.     lcdupdate
  233. _       getkey(dkAdd)
  234.             jr nz,ContrastInc
  235.         getkey(dkUp)
  236.             jr nz,ContrastInc
  237.         getkey(dkRight)
  238.             jr nz,ContrastInc
  239.         getkey(dkSub)
  240.             jr nz,ContrastDec
  241.         getkey(dkDown)
  242.             jr nz,ContrastDec
  243.         getkey(dkLeft)
  244.             jr nz,ContrastDec
  245.         getkey(dkClear)
  246.             jr z,-_
  247.     call frombackbuff
  248.     ret
  249. _   ld a,6
  250.     ld (penCol),a
  251.     ret
  252. ContrastInc:
  253.     ld a,(currentContrast)
  254.     inc a
  255.     cp 40
  256.         jp z,contrast_menu
  257.     ld (currentContrast),a
  258.     call setContrast
  259.     jp contrast_menu
  260. ContrastDec:
  261.     ld a,(currentContrast)
  262.     dec a
  263.     or a
  264.         jp z,contrast_menu
  265.     ld (currentContrast),a
  266.     call setContrast
  267.     jp contrast_menu
  268. ;sets the contrast to the value in a
  269. setContrast:
  270.     push af
  271.         ld (contrast),a
  272.         add a,$D8
  273.         or %11000000
  274.         out ($10),a
  275.     pop af
  276.     ret
  277. ;resets contrast back to original setting
  278. resContrast:
  279.     ld a,(CurrentContrast)
  280.     call setContrast
  281.     ret
  282. ;fades contrast till white
  283. FadeWhite:
  284.     push af
  285.         ld a,1
  286.         ld (CurrentContrast+1),a
  287. _           ld hl,CurrentContrast
  288.             call parse_wait
  289.             ld a,(contrast)
  290.             dec a
  291.             call setContrast
  292.             cp 5
  293.                 jr nz,-_
  294.     pop af
  295.     ret
  296. ;draws a menu based on a table.
  297. MenuRoutine:
  298.     call Flushkey
  299.     call tobackbuff ;store to backbuffer to save screen
  300.     push hl ;store input
  301.         rectangle(5,4,75,61,0) \ rectangle(4,5,76,60,0)         ;clear the box beneath the menu
  302.         largeSprite(4,4,9,57,MenuImg)   ;draw the menu item
  303.     pop hl  ;recall the input
  304.     ld a,6                  ;set
  305.     ld (penCol),a           ;x and
  306.     ld (penRow),a           ;y loc
  307.     call DrawWrappedString  ;draw it
  308.     ld b,(hl)               ;store value to b for loop
  309.     ld c,b                  ;current selected position
  310.     inc hl                  ;increase to the string
  311.     ld a,11                 ;store the correct location
  312.     ld (penRow),a           ;to y
  313. menudisploop:
  314.         ld a,16                 ;set
  315.         ld (penCol),a           ;x
  316.         ld a,(penRow)           ;get y
  317.         add a,6                 ;go to newline
  318.         ld (penRow),a           ;store y
  319.         call DrawWrappedString  ;draw it
  320.         djnz menudisploop       ;loop until b is 0
  321.     ld b,c      ;store amount of items back to b
  322.     ld c,0      ;set c to first item
  323. menukeyloop:
  324.     call menupickdraw   ;draw the menu selector
  325.     lcdupdate           ;update the screen
  326.     call Pause      ;wait until key is pressed
  327.     call menupickdraw   ;erase the menu selector
  328.     cp skUp
  329.         jr z,menuup
  330.     cp skDown
  331.         jr z,menudown
  332.     cp skClear
  333.         jr z,menucancel
  334.     cp sk2nd
  335.         jr z,_
  336.     cp skEnter
  337.         jr nz,menukeyloop
  338. _   call frombackbuff   ;restore original screen
  339.     ld a,c              ;check to see if c is the first item
  340.     or a                ;skip next loop if so
  341.         jr z,menujump
  342.     ld b,c              ;b is the selected item
  343. menucancel:
  344.         inc hl          ;increase to
  345.         inc hl          ;the next item in the jump list
  346.         djnz menucancel ;repeat until at the right item
  347. menujump:
  348.     call Flushkey
  349.     ld a,(hl)   ;store the value of the first part into a
  350.     inc hl      ;increate to the second half of the address
  351.     ld h,(hl)   ;store the second part to h
  352.     ld l,a      ;and the first to l
  353.     jp (hl)     ;jump now to the address in hl
  354. menudown:
  355.     ld a,c                  ;get the current item
  356.     inc a                   ;increase it
  357.     cp b                    ;if it is the max
  358.         jr z,menukeyloop    ;skip next step
  359.     inc c                   ;otherwise actually increase it
  360.     jr menukeyloop          ;then jump back
  361. menuup:
  362.     ld a,c                  ;get current item
  363.     cp 0                    ;if it is zero
  364.         jr z,menukeyloop    ;do nothing to it
  365.     dec c                   ;otherwise decrease it
  366.     jr menukeyloop          ;then jump back
  367. menupickdraw:
  368.     push bc                         ;don't want to effect
  369.         push af                     ;all the registers
  370.             push hl                 ;so lets push them onto the stack
  371.                 ld a,6              ;lets now set the correct x location
  372.                 call menusetl       ;and y
  373.                 ld b,8              ;and height
  374.                 ld ix,menupicker    ;and give it the right sprite
  375.                 call IPutSprite     ;draw it now!
  376.             pop hl                  ;and now we restore
  377.         pop af                      ;all the registers
  378.     pop bc                          ;back to normal that we need
  379.     ret                             ;routine done!
  380. menusetl:
  381.     push af             ;protect af
  382.         ld a,c          ;because we are puttin the current item into it
  383.         or a            ;checking if it is zero
  384.             jr z,++_    ;if so jump forward two
  385.         xor a           ;otherwise set a to zero for some math
  386.         push bc         ;protect current bc
  387.             ld b,c      ;load c into b
  388. _:
  389.                 add a,6 ;add 6 to a until done with b
  390.                 djnz -_ ;loop de loop
  391.         pop bc          ;lets get the original b back
  392. _:
  393.         add a,16        ;add the standard 16 offset
  394.         ld l,a          ;store it all to e
  395.     pop af              ;reset a
  396.     ret                 ;done setting e
  397. ;copies the gbuf to the backbuffer
  398. tobackbuff:
  399.     push hl
  400.         push de
  401.             push bc
  402.                 ld bc,767
  403.                 ld hl,AppBackupScreen
  404.                 ld d,h
  405.                 ld e,l
  406.                 ld hl,gbuf
  407.                 ldir
  408.             pop bc
  409.         pop de
  410.     pop hl
  411.     ret
  412. ;copies the backbuffer to gbuf
  413. frombackbuff:
  414.     push hl
  415.         push de
  416.             push bc
  417.                 ld bc,767
  418.                 ld hl,gbuf
  419.                 ld d,h
  420.                 ld e,l
  421.                 ld hl,AppBackupScreen
  422.                 ldir
  423.             pop bc
  424.         pop de
  425.     pop hl
  426.     ret
  427. ;outputs the string in HL at penCol and penRow and wraps it on the screen. It also allows for manual newlines with \n
  428. DrawWrappedString:
  429.     ld a, (hl)
  430.     inc hl
  431.     cp '\n'
  432.         jr z, WrapLine
  433.     cp '\r'
  434.         jr z, WrapPage
  435.     cp '\t'
  436.         jr z,Tab
  437.     or a
  438.         ret z
  439.     b_call _VPutMap
  440.     ld a,(penCol)
  441.     cp 92
  442.         jr nc,WrapLine
  443.     jr DrawWrappedString
  444. Tab:
  445.     ld a,(penCol)
  446.     add a,6
  447.     ld (penCol),a
  448.     cp 55
  449.         call nc,Newline
  450.     jr DrawWrappedString
  451. WrapLine:
  452.     call Newline
  453.     jr DrawWrappedString
  454. WrapPage:
  455.     lcdupdate
  456.     call pause
  457.     clearlcd
  458.     homeup
  459.     jr DrawWrappedString
  460. ;monospace text
  461. DrawMonospaceString:
  462.     ld a, (hl)
  463.     inc hl
  464.     cp '\n'
  465.         jr z, monoWrapLine
  466.     cp '\r'
  467.         jr z, monoWrapPage
  468.     cp '\t'
  469.         jr z,monoTab
  470.     or a
  471.         ret z
  472.     push af
  473.         ld a,(penCol)
  474.         ld b,a
  475.     pop af
  476.     push bc
  477.         b_call _VPutMap
  478.     pop bc
  479.     ld a,b
  480.     add a,6
  481.     ld (penCol),a
  482.     cp 92
  483.         jr nc,monoWrapLine
  484.     jr DrawMonospaceString
  485. monoTab:
  486.     ld a,(penCol)
  487.     add a,12
  488.     ld (penCol),a
  489.     cp 55
  490.         call nc,Newline
  491.     jr DrawMonospaceString
  492. monoWrapLine:
  493.     call Newline
  494.     jr DrawMonospaceString
  495. monoWrapPage:
  496.     lcdupdate
  497.     call pause
  498.     clearlcd
  499.     homeup
  500.     jr DrawMonospaceString
  501. ;newline, wrapps screen if necessary
  502. ;preserves af
  503. Newline:
  504.     push af
  505.         xor a
  506.         ld (penCol),a
  507.         ld a,(penRow)
  508.         add a, 6
  509.         cp 55
  510.             jr nc,NewLine_top
  511.         ld (penRow),a
  512.     pop af
  513.     ret
  514. NewLine_top:
  515.         xor a
  516.         ld (penRow),a
  517.     pop af
  518.     ret
  519. ;clears the buffer and updates
  520. ClearFull:
  521.     clearlcd
  522.     lcdupdate
  523.     ret
  524. ;clears the graphbuffer
  525. ClearBuff:
  526.     push hl
  527.         push de
  528.             push bc
  529.                 ld hl,PlotSScreen
  530.                 ld (hl),0
  531.                 ld d,h
  532.                 ld e,l
  533.                 inc de
  534.                 ld bc,767
  535.                 ldir
  536.             pop bc
  537.         pop de
  538.     pop hl
  539.     ret
  540. ;########################################
  541. ;8*16 masked sprites
  542. ;input: de = xy
  543. ;   hl = pic start
  544. putmaskedSprite:
  545.     push    hl
  546.     ld  a, d
  547.     ld  d, 0
  548.     ld  h, 0
  549.     ld  l, e
  550.     add hl, hl
  551.     add hl, de
  552.     add hl, hl
  553.     add hl, hl
  554.  
  555.     ld  e, a
  556.     srl e
  557.     srl e
  558.     srl e
  559.     add hl, de
  560.     ld  de, plotSScreen
  561.     add hl, de
  562.  
  563.     pop ix
  564.     and 7
  565.     ld  c, a
  566.     ld  b, 16
  567. maskedLp:
  568.     push    bc
  569.     ld  de, 0
  570.     ld  a, c
  571.     or  a
  572.     ld  b, c
  573.     ld  a, (ix + 16)
  574.     ld  c, (ix)
  575.     jr  z, aligned
  576. alignLp:
  577.     rra     ;neither side can bring a carry
  578.     rr  d
  579.     srl c
  580.     rr  e
  581.     djnz    alignLp
  582. aligned:
  583.  
  584.     cpl
  585.     and (hl)
  586.     or  c
  587.     ld  (hl), a
  588.     inc hl
  589.     ld  a, d
  590.     cpl
  591.     and (hl)
  592.     or  e
  593.     ld  (hl), a
  594.  
  595.     ld  de, 11
  596.     add hl, de
  597.     inc ix
  598.     pop bc
  599.     djnz    maskedLp
  600.     ret
  601. ;-----> DrawCustomRectangle
  602. ;input: h=x1 l=y2 d=x2 e=y2 a=color
  603. ;output:none
  604. DrawCustomRectangle:
  605. api_draw_square:
  606.   ld (api_line_color),a
  607. api_draw_square_noset:
  608.   ld a,h
  609.   cp 96
  610.   jr c,api_drawblock_skip1
  611.   ld h,96
  612. api_drawblock_skip1:
  613.   ld a,d
  614.   cp 96
  615.   jr c,api_drawblock_skip2
  616.   ld d,96
  617. api_drawblock_skip2:
  618.   ld a,l
  619.   cp 64
  620.   jr c,api_drawblock_skip3
  621.   ld l,64
  622. api_drawblock_skip3:
  623.   ld a,e
  624.   cp 64
  625.   jr c,api_drawblock_loop
  626.   ld e,64
  627. api_drawblock_loop:
  628.   ld a,l
  629.   cp e
  630.   ret nc
  631.   push hl
  632.   push de
  633.   ld e,l
  634.   call api_drawline_dontset
  635.   pop de
  636.   pop hl
  637.   inc l
  638.   ld a,(api_line_color)
  639.   cp %10101010
  640.   jr z,api_drawblock_dither
  641.   cp %01010101
  642.   jr nz,api_drawblock_loop
  643. api_drawblock_dither:
  644.   cpl
  645.   ld (api_line_color),a
  646.   jp api_drawblock_loop
  647. api_drawline_set:
  648.   ld (api_line_color),a
  649. api_drawline_dontset:
  650.   push hl
  651.   ld a,h
  652.   call api_drawline_getmask
  653.   ld b,a
  654.   ld a,d
  655.   call api_drawline_getmask
  656.   cpl
  657.   ld c,a
  658.   pop hl
  659.   push bc
  660.   call api_drawline_getbyte
  661.   push hl
  662.   ld h,d
  663.   ld l,e
  664.   call api_drawline_getbyte
  665.   pop de
  666.   push de
  667.   push hl
  668.   sbc hl,de
  669.   jp z,api_drawline_onebyte
  670.   ld a,l
  671.   cp 1
  672.   jp z,api_drawline_skip_inner
  673.   ld b,l
  674.   dec b
  675.   ex de,hl
  676.   inc hl
  677.   ld a,(api_line_color)
  678. api_drawline_loop_inner:
  679.   ld (hl),a
  680.   inc hl
  681.   djnz api_drawline_loop_inner
  682. api_drawline_skip_inner:
  683.   pop de
  684.   pop hl
  685.   pop bc
  686.   call api_drawline_modify
  687.   ex de,hl
  688.   ld b,c
  689.   jp api_drawline_modify
  690. api_drawline_onebyte:
  691.   pop de
  692.   pop hl
  693.   pop bc
  694.   ld a,b
  695.   and c
  696.   ld b,a
  697. api_drawline_modify:
  698.   push bc
  699.   ld a,(api_line_color)
  700.   push bc
  701.   ld c,a
  702.   ld a,b
  703.   and c
  704.   pop bc
  705.   push af
  706.   ld a,b
  707.   cpl
  708.   and (hl)
  709.   ld b,a
  710.   pop af
  711.   or b
  712.   ld (hl),a
  713.   pop bc
  714.   ret
  715. api_drawline_getbyte:
  716.   ld a,h
  717.   ld h,0
  718.   ld b,h
  719.   ld c,l
  720.   add hl,hl
  721.   add hl,bc
  722.   add hl,hl
  723.   add hl,hl
  724.   ld c,a
  725.   srl c
  726.   srl c
  727.   srl c
  728.   add hl,bc
  729.   ld bc,gbuf
  730.   add hl,bc
  731.   ret
  732. api_drawline_getmask:
  733.   and 7
  734.   ld hl,api_drawline_lut
  735.   add a,l
  736.   ld l,a
  737.   ld a,(hl)
  738.   ret
  739. api_drawline_lut:
  740.   .db %11111111
  741.   .db %01111111
  742.   .db %00111111
  743.   .db %00011111
  744.   .db %00001111
  745.   .db %00000111
  746.   .db %00000011
  747.   .db %00000001
  748. api_line_color:
  749.     db 0
  750. ;--------------------------------
  751. ;Clip Big Sprite
  752. ;by James Montelongo
  753. ;MAX SIZE: 64x64
  754. ;ix - Sprite
  755. ;b  - height
  756. ;c  - width in bytes
  757. ;d  - x
  758. ;e  - y
  759.  
  760. ClipBigSprite:
  761. ; Early out, Check if its even remotely on screen
  762.     ld a,e
  763.     cp 64
  764.     ret p
  765.     add a,b
  766.     ret m
  767.     ret z
  768.     ld a,d
  769.     cp 96
  770.     ret p
  771.     ld a,c
  772.     add a,a
  773.     add a,a
  774.     add a,a
  775.     add a,d
  776.     ret m
  777.     ret z
  778.  
  779.     ld a,e
  780.     or a
  781.     jp p,Check_clip_bottom
  782.     neg
  783.     push de
  784.     ld hl,0
  785.     ld d,l
  786.     ld e,a
  787.     bit 2,c
  788.     jr z,$+2+1
  789.     add hl,de
  790.     add hl,hl  
  791.     bit 1,c
  792.     jr z,$+2+1
  793.     add hl,de
  794.     add hl,hl  
  795.     bit 0,c
  796.     jr z,$+2+1
  797.     add hl,de
  798.     pop de
  799.     ex de,hl
  800.     add ix,de       ;Here you can save the top offset
  801.     ex de,hl
  802.     ld e,0
  803.     neg
  804.     add a,b
  805.     ld b,a
  806. Check_clip_bottom:
  807.  
  808.     ld a,e
  809.     add a,b
  810.     sub 64
  811.     jp m,Check_clip_Left
  812.     neg
  813.     add a,b
  814.     ld b,a
  815. Check_clip_Left:
  816.                 ; at this point you may want to save b
  817.     xor a
  818.     ld (bigskip),a
  819.     ld a,Clipleftsize
  820.     ld (Do_Clipleft),a
  821.     ld a,d
  822.     or a
  823.     jp p,Check_clip_right
  824.     cpl
  825.     and $F8
  826.     rra
  827.     rra
  828.     rra
  829.     ex de,hl        ;save the clipped left offset
  830.     ld e,a
  831.     ld d,0
  832.     add ix,de
  833.     ld (bigskip),a
  834.     ex de,hl
  835.     inc a
  836.     neg
  837.     add a,c
  838.     ld c,a
  839.     xor a
  840.     ld (Do_Clipleft),a
  841.     ld a,d
  842.     and $07
  843.     ld d,a
  844. Check_clip_right:
  845.  
  846.     ld a,Cliprightsize
  847.     ld (Do_Clipright),a
  848.     ld a,c
  849.     add a,a
  850.     add a,a
  851.     add a,a
  852.     add a,d
  853.     sub 96
  854.     jp m,Check_clip_middle
  855.     and $F8
  856.     rra
  857.     rra
  858.     rra
  859.     ld l,a
  860.     ld a,(bigskip)
  861.     add a,l
  862.     inc a
  863.     ld (bigskip),a
  864.     neg
  865.     add a,c
  866.     ld c,a
  867.     xor a
  868.     ld (Do_Clipright),a
  869. Check_clip_middle:
  870.                 ; This is where C should be saved.
  871.     xor a
  872.     ld (Do_ClipMiddle),a
  873.     ld a,c
  874.     or a
  875.     jp nz,dontskipmiddle
  876.     ld a,ClipMiddlesize
  877.     ld (Do_ClipMiddle),a
  878. dontskipmiddle:
  879.     ld l,e
  880.     ld a,d 
  881.     ld h,0
  882.     ld d,h
  883.     add hl,hl
  884.     add hl,de
  885.     add hl,hl
  886.     add hl,hl
  887.     ld e,a
  888.     and $07
  889.     xor 7
  890.     ld (BigRot1),a
  891.     ld (BigRot2),a
  892.     ld (BigRot3),a
  893.     add a,a
  894.     ld (clipbigrot1),a
  895.     ld a,$ff
  896. clipbigrot1 = $+1
  897.     jr $
  898.     srl a
  899.     srl a
  900.     srl a
  901.     srl a
  902.     srl a
  903.     srl a
  904.     srl a
  905.     srl e
  906.     srl e
  907.     srl e
  908.     add hl,de
  909.     ld de,gbuf
  910.     add hl,de
  911.                 ; This is where gbuf offset should be saved.
  912.     ld d,a
  913.     cpl
  914.     ld e,a
  915.                 ;masks should be saved to
  916. BigSpriteRow:
  917.     push bc
  918.     push hl
  919.     ld b,c
  920. Do_Clipleft = $+1
  921.     jr Clipleft
  922.     ld a,(ix)
  923.     inc ix
  924. BigRot1 = $+1
  925.     jr $
  926.     rrca
  927.     rrca
  928.     rrca
  929.     rrca
  930.     rrca
  931.     rrca
  932.     rrca
  933. BigMask0:
  934.     and e
  935.     or (hl)
  936.     ld (hl),a
  937. Clipleft:
  938. Clipleftsize = Clipleft-(Do_Clipleft+1)
  939.  
  940. Do_ClipMiddle = $+1
  941.     jr $+2
  942. BigSpriteloop:
  943.     ld a,(ix)
  944.     inc ix
  945. BigRot2 = $+1
  946.     jr $
  947.     rrca
  948.     rrca
  949.     rrca
  950.     rrca
  951.     rrca
  952.     rrca
  953.     rrca
  954.     ld c,a
  955. BigMask1:
  956.     and d
  957.     or (hl)
  958.     ld (hl),a
  959.     inc hl
  960.     ld a,c
  961. BigMask2:
  962.     and e
  963.     or (hl)
  964.     ld (hl),a
  965.     djnz BigSpriteloop
  966. ClipMiddle:
  967. ClipMiddlesize = ClipMiddle-(Do_ClipMiddle+1)
  968.  
  969. Do_ClipRight = $+1
  970.     jr ClipRight
  971.     ld a,(ix)
  972. BigRot3 = $+1
  973.     jr $
  974.     rrca
  975.     rrca
  976.     rrca
  977.     rrca
  978.     rrca
  979.     rrca
  980.     rrca
  981. BigMask3:
  982.     and d
  983.     or (hl)
  984.     ld (hl),a
  985. ClipRight:
  986. Cliprightsize = ClipRight-(Do_ClipRight+1)
  987.     pop hl
  988.  
  989.     ld bc,12            ;width of the screen
  990.     add hl,bc
  991.  
  992. bigskip = $+1
  993.     ld bc,0
  994.     add ix,bc
  995.     pop bc
  996.     djnz BigSpriteRow
  997.     ret
  998. clearTextBuff:  ;clears the textbuffer completely for things that don't know if they are really going to write to it.
  999.     push bc
  1000.         push de ;poop
  1001.             push hl
  1002.                 ld hl,text_buffer
  1003.                 ld de,text_buffer+1
  1004.                 ld bc,531-1
  1005.                 ld (hl),0
  1006.                 ldir
  1007.             pop hl
  1008.         pop de
  1009.     pop bc
  1010.     ret
Advertisement
Add Comment
Please, Sign In to add comment