?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ;select word from table
  2. ;by index
  3. ;in A - index HL - table
  4. ;out HL -adress from table
  5.  
  6. sel_word:
  7.         add a,a
  8.         ld c,a
  9.         ld b,0
  10.         add hl,bc
  11.         ld a,(hl)
  12.         inc hl
  13.         ld h,(hl)
  14.         ld l,a
  15.         ret
  16.  
  17. ;hl-src de-dest string limiter -  0
  18. copystr_hlde:
  19.         ld a,(hl)
  20.         and a
  21.         ret z
  22.         ld (de),a
  23.         inc hl
  24.         inc de
  25.         jr copystr_hlde
  26. ;------------------------
  27. ;-setup interrupt
  28. int_set:
  29.         di
  30.         ld hl,0x0038
  31.         ld de,int_orig
  32.         ld bc,5
  33.         ldir
  34.         ld hl,0x0038
  35.         ld a,0xC3 ;jp
  36.         ld (hl),a
  37.         inc hl
  38.         ld de,int_proc
  39.         ld a,e
  40.         ld (hl),a
  41.         inc hl
  42.         ld a,d
  43.         ld (hl),a
  44.         ei
  45.         ret
  46.  
  47. int_reset:
  48.         di
  49.         ld de,0x0038
  50.         ld hl,int_orig
  51.         ld bc,3
  52.         ldir
  53.         ei
  54.         ret
  55.  
  56. int_proc
  57.         push af
  58.         ex af,af'
  59.        push af
  60.        push bc
  61.        push de
  62.        push hl
  63.        push ix
  64.        push iy
  65.        exx
  66.        push bc
  67.        push de
  68.        push hl
  69.  
  70. ;        ld a,1
  71. ;        out (0xfe),a
  72.  
  73.        ld a,(setpalflag)
  74.        or a
  75.        call nz,setpal_proc
  76. ;       ld a,(setscreenflag)
  77. ;       or a
  78. ;       call nz,setscreen_proc
  79.        GET_KEY
  80.        ld a,c
  81.        ld (keyreg),a
  82.        OS_GETKEYMATRIX
  83.        ld (keymatrixbc),bc
  84.        ld (keymatrixde),de
  85.        ld (keymatrixhl),hl
  86.        ld (keymatrixix),ix
  87.  
  88.  
  89.        ld a,0
  90. wlock equ $-1
  91.        and a      
  92.        CALL nz,anim_wait
  93.  
  94.  
  95.        ld a,0
  96. alock equ $-1
  97.        and a      
  98.        CALL nz,anim_eyes
  99.  
  100. ;        ld a,0
  101. ;        out (0xfe),a
  102.  
  103.        ld a,0
  104. screenswapper: equ $-1
  105.        and a
  106.        call nz,switchscreens
  107.  
  108.        pop hl
  109.        pop de
  110.        pop bc
  111.        exx
  112.        pop iy
  113.        pop ix
  114.        pop hl
  115.        pop de
  116.        pop bc
  117.        pop af
  118.        ex af,af'
  119.         pop af
  120. int_orig ds 5
  121.         jp 0x0038+5        
  122.  
  123. no_mus
  124.           call setmusicpage
  125.           ld a,(music_buf)
  126.           ld hl,PLR_MUTE
  127.           OS_SETMUSIC
  128.           call unsetmusicpage
  129.           halt
  130.           ret
  131. ;==========================
  132. switchscreens:
  133.         ld e,1
  134. swscrsw equ $-1
  135.         push de
  136.         OS_SETSCREEN
  137.         pop de
  138.         ld a,e
  139.         xor 1
  140.         ld (swscrsw),a
  141.         ret
  142.        
  143. ;---------------------
  144. filecreateeerror:
  145.         ld hl,txt_fcreateerror
  146.         jr openerror        
  147. filewriteerror:
  148.         call closestream_file
  149.         ld hl,txt_fwriteerror
  150.         jr openerror
  151. filereaderror:
  152.         call closestream_file
  153.         ld hl,txt_freaderror
  154.         jr openerror
  155. dirchangeerror
  156.         ld hl,txt_dircherror
  157.         jr openerror
  158. fileopenerror
  159.         ld hl,txt_fopenerror
  160. openerror:
  161.         push hl
  162.         ld e,6+0x80
  163.         OS_SETGFX
  164.         ld e,0
  165.         OS_CLS
  166.         pop  hl
  167.         call print_hl
  168.         ld hl,buf
  169.         call print_hl
  170.         ld hl,txt_nl
  171.         call print_hl
  172.         YIELDGETKEYLOOP
  173.         jp cmd_quit
  174.  
  175.  
  176. memoryerror
  177.         OS_CLOSEHANDLE
  178.         ld e,6+0x80
  179.         OS_SETGFX
  180.         ld e,0
  181.         OS_CLS
  182.         ld hl,txt_memoryerror
  183.         call print_hl
  184.         YIELDGETKEYLOOP
  185.         jp cmd_quit
  186.  
  187.  
  188. cmd_quit
  189. ;;      call closestream_file
  190.         ld e,6+0x80
  191.         OS_SETGFX
  192.         call int_reset
  193. ;;       call disablemusic
  194.         QUIT        
  195.  
  196. ;----------------------------------------        
  197. load_mus
  198.  
  199.         ld b,0
  200. old_mus EQU $-1
  201.         cp b
  202.         ret z
  203.         ld (old_mus),a
  204.  
  205.         and a
  206.         jp z,no_mus
  207.  
  208.        
  209.         call calc_mus
  210.  
  211.         call no_mus
  212.        
  213.         ;generate path to music file in 'buf'
  214.         ld hl,mus_path1
  215.         ld de,buf
  216.         call copystr_hlde ;'copy path  'mus/' '
  217.        
  218.         ld a,(mus_mode)
  219.         ld hl,mus_modes
  220.         call sel_word
  221.         call copystr_hlde ;copy "aym / s98 path"
  222.         ld hl,mus_path2
  223.         call copystr_hlde ;copy name without ext
  224.        
  225.         ld a,(mus_mode)
  226.         ld hl,plr_ext
  227.         call sel_word
  228.         call copystr_hlde  ;copy file ext
  229.         xor a
  230.         ld (de),a  ;string terminator
  231.  
  232.  
  233.  
  234.         call setmusicpage
  235.  
  236.                 ld de,buf
  237.                 call openstream_file
  238.                 or a
  239.                 jp nz,fileopenerror
  240.  
  241.                 ld hl,0x3000 ;len
  242.                 ld de,module ;addr
  243.                 call readstream_file
  244.                 or a
  245.                 jp nz,filereaderror
  246.  
  247.                 call closestream_file
  248.  
  249.                 ld a,0b00100000
  250.                 ld (SETUP),a
  251.                 ld hl,module
  252.  
  253.                 call PLR_INIT        ;init music
  254.  
  255.                 ld a,(music_buf)
  256.                 ld hl,PLR_PLAY
  257.                 OS_SETMUSIC        
  258.         jp unsetmusicpage
  259.  
  260. calc_mus:
  261.         call a_to_dec
  262.  
  263.         LD (mus_path2+5),A
  264.         LD A,B
  265.         LD (mus_path2+4),A
  266.         RET        
  267.  
  268. a_to_dec:
  269.         CP 30
  270.         JR C,calc_m0
  271.         SUB 30
  272.         LD B,"3"
  273.         JR calc_mus_f
  274. calc_m0   CP 20
  275.         JR C,calc_m1
  276.         SUB 20
  277.         LD B,"2"
  278.         jr calc_mus_f
  279. calc_m1   CP 10
  280.         JR C,calc_m2
  281.         SUB 10
  282.         LD B,"1"
  283.         JR calc_mus_f
  284. calc_m2   LD B,"0"
  285. calc_mus_f:
  286.          ADD A,"0"
  287.          ret
  288. ;------------------
  289. setmusicpage
  290.         OS_GETMAINPAGES
  291.         ld a,e
  292.         ld (tbank1),a
  293.         ld a,(music_buf)
  294.         SETPG4000
  295.         ret
  296.  
  297. unsetmusicpage
  298.         ld a,(tbank1)
  299.         SETPG4000
  300.         ret
  301.  
  302. ;---------------------
  303. setfontpage
  304.         OS_GETMAINPAGES
  305.         ld a,h
  306.         ld (tbank2),a
  307.         ld a,(font_page)
  308.         SETPG8000
  309.         ret
  310.  
  311. unsetfontpage
  312.         ld a,(tbank2)
  313.         SETPG8000
  314.         ret
  315. ;---------------------
  316. store8000c000
  317.         OS_GETMAINPAGES
  318.         ld a,h
  319.         ld (tbank2),a
  320.         ld a,l
  321.         ld (tbank3),a
  322.         ret
  323.  
  324. restore8000c000
  325.         ld a,(tbank2)
  326.         SETPG8000
  327.         ld a,(tbank3)
  328.         SETPGC000        
  329.         ret
  330. ;========================
  331. storec000
  332.         OS_GETMAINPAGES
  333.         ld a,l
  334.         ld (tbank3),a
  335.         ret
  336.  
  337. restorec000
  338.         ld a,(tbank3)
  339.         SETPGC000        
  340.         ret
  341. ;========================
  342. store8000
  343.         OS_GETMAINPAGES
  344.         ld a,h
  345.         ld (tbank2),a
  346.         ret
  347.  
  348. restore8000
  349.         ld a,(tbank2)
  350.         SETPG8000        
  351.         ret
  352. ;========================
  353.  
  354.  
  355.  
  356. getkey
  357.         ld a,(keyreg)
  358.         ret
  359.  
  360.  
  361. waitkey_a
  362.         ld a,1
  363.         ld (wlock),a
  364.         call waitkey
  365.         push af
  366.         xor a
  367.         ld (wlock),a
  368.         pop af
  369.         ret
  370.  
  371. waitkey
  372.  
  373. waitkey_unpress ;Wait for enter unpress
  374.         ld a,(keymatrixix+1)
  375.         bit 0,a
  376.         jr z,waitkey_unpress
  377. waitkey_loop
  378.         call getkey
  379.         cp NOKEY
  380.         jr z,waitkey_loop
  381. waitkey0
  382.         ld (lastkey),a
  383.         call getkey
  384.         cp NOKEY
  385.         jr nz,waitkey0 ; purge key buffer
  386.         ld a,(lastkey)
  387.         ret
  388.         ;cp key_esc
  389.         ;jp z,cmd_quit
  390.         ;ret
  391. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  392.  
  393. change_cp1 ;#
  394.             LD A,186
  395.             RET
  396. change_cp2   ;@
  397.           LD A,188
  398.           RET
  399. change_cp
  400.          PUSH HL,DE
  401.          LD HL,TABLE_W
  402. CODEPAGE EQU $-2
  403.          SUB 128
  404.          LD D,0
  405.          LD E,A
  406.          ADD HL,DE
  407.          LD A,[HL]
  408.          POP DE,HL
  409.          RET
  410.  
  411. TABLE_W  DS 40,32
  412.          DB 134
  413.          DS 15,32
  414.          DB 194
  415.          DS 7,32
  416.          DB 129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160
  417.          DB 161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,188,189,190,191,192,193
  418.  
  419. TABLE_J  DS 13,32
  420.          DB 186,188 ;╨бтА░ ╨б╨Й        141 142
  421.          DS 15,32
  422.          DB 186,188 ;╨бтА░ ╨б╨Й        158 159
  423.          DB 189,190,191,192,193,129,130,131,132,133,134,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154
  424.          DB 155,156,157,158,159,160,161,162,163,164,165,166,194,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185
  425.          DB 186,188,189,190,191,192,193
  426.          DS 6,32
  427.          DB 143
  428.          DB 32,32,150 ;╨а╥Р
  429.          DB 32,154,155
  430.  
  431. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  432. ;in - none/ out - hl -point to script name to load
  433. save_to_globals:
  434.         ld hl,buf
  435.         ld de,GLOBVARS
  436.         ld b,0
  437. _stg_loop:
  438.         ld a,(hl)
  439.         ld (de),a
  440.         inc hl
  441.         inc hl
  442.         inc de
  443.         djnz _stg_loop
  444.         ld bc,6
  445.         add hl,bc
  446.         ret
  447. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  448. ;in - none/ out - hl -point to script name to load
  449. globals_to_save:
  450.         ld hl,buf
  451.         ld de,GLOBVARS
  452.         ld b,0
  453. _gts_loop:
  454.         ld a,(de)
  455.         ld (hl),a
  456.         inc hl
  457.         ld (hl),0
  458.         inc hl
  459.         inc de
  460.         djnz _gts_loop
  461.         ld (hl),0
  462.         inc hl
  463.         ld (hl),0
  464.         inc hl
  465.         ld (hl),0
  466.         inc hl
  467.         ld (hl),0
  468.         inc hl
  469.         ld (hl),0
  470.         inc hl
  471.         ld (hl),0
  472.         inc hl          ;copy global variables to save
  473.  
  474.         ld de,LOADED
  475.         ex de,hl
  476.         call copystr_hlde
  477.         xor a
  478.         ld (de),a ;copy loaded ovl name
  479.         ret        
  480. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  481. _ftp:
  482.        LD HL,#4002  ;FIRST TEXT POINTER
  483.         LD B,(HL)
  484.         INC HL
  485.         LD H,(HL)
  486.         LD A,#40
  487.         ADD A,H
  488.         LD H,A
  489.         LD L,B
  490.         LD B,(HL)
  491.         INC HL
  492.         LD H,(HL)
  493.         LD A,#40
  494.         ADD A,H
  495.         LD H,A
  496.         LD L,B  ;HL-FIRST TEXT ADRESS
  497.         RET        
  498. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  499. ;ыбкс╜нємбмсди хм┐ явлцд╖цои юбвщдаэ╜жэ╢аЁРма
  500. _precache:
  501.         LD IX,ILINK
  502.         LD A,1
  503.         LD (MM),A
  504.         LD (SM),A
  505.         LD HL,#4000
  506.         LD L,(HL)
  507.         LD E,(HL)
  508.         INC HL
  509.         LD D,(HL)
  510.         LD HL,#4002
  511.         LD L,(HL)
  512.         INC DE
  513.         LD A,E
  514.         OR D
  515.         RET Z
  516.         DEC DE
  517.         LD A,E
  518.         OR D
  519.         RET Z
  520.         LD A,E
  521.         CP (HL)
  522.         JR NZ,$+6
  523.         INC HL
  524.         LD A,D
  525.         CP (HL)
  526.         RET Z
  527.         LD HL,#4004
  528.         LD L,(HL)
  529.         LD E,(HL)
  530.         INC HL
  531.         LD D,(HL)
  532.         LD A,D
  533.         OR E
  534.         RET Z
  535.         DEC HL
  536.         LD (TREEE),HL
  537.         LD DE,#4006
  538.         LD A,(DE)
  539.         LD (LIMIT4),A;LOW
  540.         LD A,D
  541.         LD (LIMIT3),A;HI
  542.         LD DE,#4000
  543.         LD A,(DE)
  544.         LD E,A
  545.         LD (STRUCTURE),DE
  546. PRECAH  LD HL,(TREEE)
  547.         LD A,H
  548.         CP 0
  549. LIMIT3  EQU $-1
  550.         JR NZ,PRECAH1
  551.         LD A,L
  552.         CP 0
  553. LIMIT4  EQU $-1
  554.         RET Z   ;END OF TREE
  555.  
  556. PRECAH1
  557.         LD E,(HL)
  558.         INC HL
  559.         LD D,(HL)
  560.         LD A,#40
  561.         ADD A,D
  562.         LD D,A
  563.  
  564.         LD A,(DE)
  565.         LD (STORE),A
  566.         INC DE
  567.         LD A,(DE)
  568.         LD (STORE+1),A
  569.         INC DE
  570.         LD A,(DE)
  571.         INC A
  572.         JR NZ,PRECAH2
  573.         INC DE
  574.         LD A,(DE)
  575.         INC A
  576.         JR Z,PRECAH3 ;NONE OF SUBMENU
  577.         DEC DE
  578.  
  579. PRECAH2 LD A,(DE)
  580.         LD (STORE1),A
  581.         INC DE
  582.         LD A,(DE)
  583.         LD (STORE1+1),A
  584.         DEC DE
  585.         PUSH DE
  586.         LD A,4
  587.         CALL SEARCHING
  588.         LD A,1
  589. MM      EQU $-1
  590.         LD (IX),A
  591.         INC IX
  592.         LD A,1
  593. SM      EQU $-1
  594.         LD (IX),A
  595.         INC IX
  596.         LD (IX),L
  597.         INC IX
  598.         LD (IX),H
  599.         INC IX
  600.         LD A,(SM)
  601.         INC A
  602.         LD (SM),A
  603.         POP DE
  604.         INC DE,DE
  605.         LD A,(DE)
  606.         INC A
  607.         JR NZ,PRECAH2
  608.         INC DE
  609.         LD A,(DE)
  610.         DEC DE
  611.         INC A
  612.         JR NZ,PRECAH2
  613.  
  614. PRECAH4 LD A,1
  615.         LD (SM),A
  616.         LD HL,MM
  617.         INC (HL)
  618.         LD HL,0
  619. TREEE   EQU $-2
  620.         INC HL,HL
  621.         LD (TREEE),HL
  622.         JP PRECAH
  623. PRECAH3 LD HL,#FFFF
  624.         LD (STORE1),HL
  625.         LD A,2
  626.         CALL SEARCHING
  627.         LD A,(MM)
  628.         LD (IX),A
  629.         INC IX
  630.         XOR A
  631.         LD (IX),A
  632.         INC IX
  633.         LD (IX),L
  634.         INC IX
  635.         LD (IX),H
  636.         INC IX
  637.         JR PRECAH4
  638. STORE   DW 0
  639. STORE1  DW 0
  640.  
  641. SEARCHING
  642.           LD (SEAR2-1),A
  643.           LD HL,0
  644. STRUCTURE EQU $-2
  645. SEAR1   PUSH HL
  646.          LD E,(HL)
  647.         INC HL
  648.         LD D,(HL)
  649.         LD A,#40
  650.         ADD A,D
  651.         LD D,A
  652.         LD HL,STORE
  653.         LD B,4
  654. SEAR2   LD A,(DE)
  655.         CP (HL)
  656.         JR NZ,SEAR3
  657.         INC DE
  658.         INC HL
  659.         DJNZ SEAR2
  660.         POP HL
  661.         RET
  662. SEAR3   POP HL
  663.         INC HL,HL
  664.         JR SEAR1
  665. ;---------------------------------------------------------------
  666.  
  667. ;PRINT ROUTEINES WITH TOKENS
  668. _print
  669.         ld a,(script_buf1)
  670.         SETPG4000
  671.         ld a,(script_buf2)
  672.         SETPG8000
  673.  
  674.  
  675.  
  676.         LD A,(HL)
  677.         INC HL
  678.         CP 32
  679.         JR C,PRINT1
  680.         CP "%"
  681.         JR Z,_print_hero_name
  682.  
  683.         cp 128
  684.         call nc,change_cp
  685.         CP "#"
  686.         call z,change_cp1
  687.         CP "@"
  688.         call z,change_cp2
  689.  
  690. PRINT0  SUB 32
  691.         PUSH HL
  692.         CALL _type
  693.         POP HL
  694.         JR _print
  695.  
  696. PRINT1  PUSH HL
  697.         LD HL,TOKENTABLE
  698.         LD C,A
  699. PRINT2  LD A,(HL)
  700.         INC HL
  701.         CP 255
  702.         JR Z,PRINT4     ;END OF TABLE
  703.         CP C
  704.         JR Z,PRINT3     ;CODE FOUND
  705.         INC HL
  706.         INC HL
  707.         JR PRINT2
  708. PRINT3  LD A,(HL)
  709.         INC HL
  710.         LD H,(HL)
  711.         LD L,A
  712.         EX (SP),HL
  713.         RET
  714. PRINT4  POP HL
  715.         JR _print
  716.  
  717. PRINT5  LD C,A
  718. PRINT6  LD A,(HL)
  719.         INC HL
  720.         CP 255
  721.         JR Z,PRINT8     ;END OF TABLE
  722.         CP C
  723.         JR Z,PRINT7     ;CODE FOUND
  724.         INC HL
  725.         INC HL
  726.         JR PRINT6
  727. PRINT7  LD A,(HL)
  728.         INC HL
  729.         LD H,(HL)
  730.         LD L,A
  731.         EX (SP),HL
  732.         RET
  733. PRINT8  POP HL
  734.         JP _print
  735.  
  736. _print_hero_name
  737.         INC HL,HL,HL
  738.         PUSH HL
  739.  
  740.         ld hl,TABLE_W
  741.         ld (CODEPAGE),HL
  742.  
  743.  
  744.        
  745.         ld a,(language)
  746.         ld hl,loc_hero_name
  747.         call sel_word    ;hl - point to localized name
  748.  
  749. PRINTA  LD A,(HL)
  750.         INC HL
  751.         AND A
  752.         JR Z,PRINTB
  753.  
  754.         CP 128
  755.         CALL NC,change_cp
  756.  
  757.         SUB 32
  758.         PUSH HL
  759.         CALL _type
  760.         POP HL
  761.         JR PRINTA
  762. PRINTB  LD HL,TABLE_J
  763.         ld (CODEPAGE),HL
  764.         POP HL
  765.         JP _print        
  766.  
  767. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  768. TOKENTABLE
  769.         DB 00
  770.         DW ENDTEXT                              ;++++
  771.         DB 01
  772.         DW WINCLR  ;IF PRESSED KEY              ;++++
  773.         DB 03
  774.         DW _print   ;SKIP UNKNOWN COMMAND       ;++++
  775.         DB 04
  776.         DW LOADOVL  ;04NAM_000.OVL              ;++++
  777.         DB 06
  778.         DW SHOWSCR
  779.         DB 07
  780.         DW SELMUSIC ;07XX                       ;++++
  781.         DB 08
  782.         DW WAITKEY_SUB                          ;++++
  783.         DB 09
  784.         DW WAITKEY_SUB_LINEFEED                          ;++++
  785.         DB #0A
  786.         DW LINEFEED                             ;++++
  787.         DB #0F
  788.         DW EXITLIGHT                            ;-
  789.         DB #10
  790.         DW EXITDARK     ;GAME OVER              ;++++
  791.         DB #13
  792.         DW FLASH ;#16XX XX-BLINKS               ;++++
  793.         DB #14
  794.         DW PAUSE                                ;++++
  795.         DB #18
  796.         DW SHAKE ;#18XX XX-SHAKES               ;++++
  797.         DB #0B
  798.         DW GROUP0B
  799.         DB #0C
  800.         DW GROUP0C
  801.         DB #11
  802.         DW GROUP11
  803.         DB #12
  804.         DW GROUP12
  805.         DB #FF
  806. TOKENTABLE0C
  807.              DB 01
  808.              DW GLOBTOLOC                       ;++++
  809.              DB 02
  810.              DW LOCTOGLOB                       ;++++
  811.              DB 03
  812.              DW GLOBLET                         ;++++
  813.              DB 255
  814.  
  815. TOKENTABLE0B
  816.         DB 01
  817.         DW ADDNUM                               ;++++
  818.         DB 2
  819.         DW ADDVAR                               ;++++
  820.         DB 3
  821.         DW SUBVAR                               ;++++
  822.         DB 5
  823.         DW LOCLET                               ;++++
  824.         DB 6
  825.         DW SUBSTRACT                            ;++++
  826.         DB 7
  827.         DW SUBNUM                               ;++++
  828.         DB 8
  829.         DW COMPAND                              ;++++
  830.         DB 9
  831.         DW COMPOR                               ;++++
  832.         DB #0A
  833.         DW TRUECONT                             ;++++
  834.         DB #0B
  835.         DW GRPAND                               ;++++
  836.         DB #0C
  837.         DW GRPOR                                ;++++
  838.         DB #14
  839.         DW RANDOMIZE                            ;++++
  840.         DB #32
  841.         DW ISPOSITIVEGOTO                       ;++++
  842.         DB #33
  843.         DW ISZEROGOTO                           ;++++
  844.         DB #34
  845.         DW ISNEGATIVEGOTO                       ;++++
  846.         DB #35
  847.         DW ISNOTZEROGOTO                         ;++++
  848.         DB #36
  849.         DW GOTO                                 ;++++
  850.         DB #39
  851.         DW EXPANDGOTO                           ;++++
  852.         DB 255
  853. TOKENTABLE11
  854.         DB      02
  855.         DW      SHOWDOUBLESCR
  856. TOKENTABLE12
  857.         DB 01
  858.         DW MENUOFF                              ;????
  859.         DB 02
  860.         DW MENUON                               ;????
  861.         DB 04
  862.         DW SUBMENUOFF                           ;????
  863.         DB 05
  864.         DW SUBMENUON                            ;????
  865.         DB 255
  866.  
  867. GROUP0C LD DE,TOKENTABLE0C
  868.         JR GROUPS
  869. GROUP0B LD DE,TOKENTABLE0B
  870.         JR GROUPS
  871. GROUP11 LD DE,TOKENTABLE11
  872.         JR GROUPS
  873. GROUP12 LD DE,TOKENTABLE12
  874.         JR GROUPS
  875. GROUPS  LD A,(HL)
  876.         INC HL
  877.         PUSH HL
  878.         EX DE,HL
  879.         JP PRINT5
  880. ENDTEXT
  881. SUBLOCK XOR A
  882.         JP NC,WINCLR1
  883.         LD A,#AF
  884.         LD (SUBLOCK),A
  885. RETURN  LD HL,0
  886.         ;CALL WINCLR1
  887.         JP _print
  888.  
  889.  
  890. ;=;=;=;=;=;=;=;=;=;=;
  891. SELMUSIC PUSH HL
  892.         LD A,(HL)
  893.         CALL load_mus
  894.         POP HL
  895.         INC HL
  896.         JP _print
  897. ;;;;====
  898. WAITKEY_SUB
  899. ;TODO  - add  'wait' animation enable | disable
  900.         push hl
  901.         call waitkey_a
  902.         pop hl
  903.         jp _print
  904. WAITKEY_SUB_LINEFEED
  905. ;TODO  - add  'wait' animation enable | disable
  906.         push hl
  907.         call waitkey_a
  908.         pop hl
  909. ;;;;====
  910. LINEFEED LD BC,(CORDS)
  911.          INC B
  912.         LD C,0
  913.          CALL _pradd
  914.          JP _print
  915. ;;;;====
  916. WINCLR  CALL WINCLR1
  917.         JP _print
  918.  
  919. WINCLR1 CALL waitkey_a
  920. WINCLR2
  921.         PUSH HL
  922.         CALL _clear_textbox  ;-0-0-3423566400------------------
  923.         POP HL
  924. COOOR   LD BC,#1300
  925.         CALL _pradd
  926.         ret
  927. ;;;;;;=====
  928. LOADOVL POP DE
  929.         ld de,OVL
  930.         call copystr_hlde
  931.         xor a
  932.         ld (DE),a
  933.         JP BEG
  934. ;;;;;;=====
  935. PAUSE
  936.         LD A,(HL)
  937.         LD B,A
  938.         INC HL
  939.         PUSH HL
  940.         RLCA
  941.         LD B,A
  942. PAUSE1  HALT
  943.         HALT
  944.         HALT
  945.         HALT
  946.         DJNZ PAUSE1
  947.         call WINCLR2
  948.         POP HL
  949.         JP _print
  950. ;;;;;-------------
  951.  
  952. GLOBTOLOC
  953.         LD A,(HL);LOC
  954.         INC HL
  955.         LD B,(HL);GLOB
  956.         INC HL
  957.         PUSH HL
  958.         LD H,HIGH GLOBVARS
  959.         LD L,B
  960.         LD C,(HL)
  961.         LD H,HIGH LOCVARS
  962.         LD L,A
  963.         LD (HL),C
  964.         POP HL
  965.         JP _print
  966.  
  967. LOCTOGLOB
  968.         LD A,(HL)
  969.         INC HL
  970.         LD B,(HL)
  971.         INC HL
  972.         PUSH HL
  973.         LD H,HIGH LOCVARS
  974.         LD L,B
  975.         LD C,(HL)
  976.         LD H,HIGH GLOBVARS
  977.         LD L,A
  978.         LD (HL),C
  979.         POP HL
  980.         JP _print
  981.  
  982. GLOBLET LD A,(HL)
  983.         INC HL
  984.         LD B,(HL)
  985.         INC HL
  986.         PUSH HL
  987.         LD H,HIGH GLOBVARS
  988.         LD L,A
  989.         LD (HL),B
  990.         POP HL
  991.         JP _print        
  992.  
  993. LOCLET LD A,(HL)
  994.         INC HL
  995.         LD B,(HL)
  996.         INC HL
  997.         PUSH HL
  998.         LD H,HIGH LOCVARS
  999.         LD L,A
  1000.         LD (HL),B
  1001.         POP HL
  1002.         JP _print
  1003.  
  1004. ADDNUM  LD A,(HL)
  1005.         INC HL
  1006.         LD B,(HL)
  1007.         INC HL
  1008.         PUSH HL
  1009.         LD H,HIGH LOCVARS
  1010.         LD L,A
  1011.         LD A,(HL)
  1012.         ADD A,B
  1013.         LD (HL),A
  1014.         POP HL
  1015.         JP _print
  1016. ADDVAR  LD A,(HL)
  1017.         INC HL
  1018.         LD B,(HL)
  1019.         INC HL
  1020.         PUSH HL
  1021.         LD H,HIGH LOCVARS
  1022.         LD L,B
  1023.         LD B,(HL)
  1024.         LD L,A
  1025.         LD A,(HL)
  1026.         ADD A,B
  1027.         LD (HL),A
  1028.         POP HL
  1029.         JP _print
  1030.  
  1031. SUBVAR  LD A,(HL)
  1032.         INC HL
  1033.         LD B,(HL)
  1034.         INC HL
  1035.         PUSH HL
  1036.         LD H,HIGH LOCVARS
  1037.         LD L,B
  1038.         LD B,(HL)
  1039.         LD L,A
  1040.         LD A,(HL)
  1041.         SUB B
  1042.         LD (HL),A
  1043.         POP HL
  1044.         JP _print
  1045.  
  1046. SUBNUM  LD D,(HL);X
  1047.         INC HL
  1048.         LD A,(HL)  ;Y
  1049.         INC HL
  1050.         LD B,(HL)  ;Z
  1051.         INC HL
  1052.         PUSH HL
  1053.         LD H,HIGH LOCVARS
  1054.         LD L,A
  1055.         LD A,(HL)
  1056.         SUB B
  1057.         LD L,D
  1058.         LD (HL),A
  1059.         POP HL
  1060.         JP _print
  1061.  
  1062. SUBSTRACT LD D,(HL);X
  1063.         INC HL
  1064.         LD A,(HL)  ;Y
  1065.         INC HL
  1066.         LD B,(HL)  ;Z
  1067.         INC HL
  1068.         PUSH HL
  1069.         LD H,HIGH LOCVARS
  1070.         LD L,A
  1071.         LD A,(HL)
  1072.         LD L,B
  1073.         LD B,(HL)
  1074.         SUB B
  1075.         LD L,D
  1076.         LD (HL),A
  1077.         POP HL
  1078.         JP _print
  1079.  
  1080. COMPAND LD D,(HL)
  1081.         INC HL
  1082.         LD A,(HL)
  1083.         INC HL
  1084.         LD B,(HL)
  1085.         INC HL
  1086.         PUSH HL
  1087.         LD H,HIGH LOCVARS
  1088.         LD L,A
  1089.         LD A,(HL)
  1090.         CP 1
  1091.         JP M,COMPAND1
  1092.         LD L,B
  1093.         LD A,(HL)
  1094.         CP 1
  1095.         JP M,COMPAND1
  1096.         LD A,1
  1097.         JR COMPAND1+1
  1098. COMPAND1 XOR A
  1099.         LD L,D
  1100.         LD (HL),A
  1101.          POP HL
  1102.         JP _print
  1103.  
  1104. COMPOR  LD D,(HL)
  1105.         INC HL
  1106.         LD A,(HL)
  1107.         INC HL
  1108.         LD B,(HL)
  1109.         INC HL
  1110.         PUSH HL
  1111.         LD H,HIGH LOCVARS
  1112.         LD L,A
  1113.         LD A,(HL)
  1114.         CP 1
  1115.         JP P,COMPOR0
  1116.         LD L,B
  1117.         LD A,(HL)
  1118.         CP 1
  1119.         JP P,COMPOR0
  1120.         XOR A
  1121.         JR COMPOR1
  1122. COMPOR0 LD A,1
  1123. COMPOR1 LD L,D
  1124.         LD (HL),A
  1125.         POP HL
  1126.         JP _print
  1127.  
  1128.  
  1129. GRPAND  LD B,(HL)
  1130.         DEC B
  1131.         INC HL
  1132.         LD D,(HL)
  1133.         INC HL
  1134. GRPAND0 LD E,(HL)
  1135.         INC HL
  1136.         PUSH HL
  1137.         LD H,HIGH LOCVARS
  1138.         LD L,D
  1139.         LD A,(HL)
  1140.         CP 1
  1141.         JP M,GRPAND1
  1142.         LD L,E
  1143.         LD A,(HL)
  1144.         CP 1
  1145.         JP M,GRPAND1
  1146.         LD A,1
  1147.         JR GRPAND1+1
  1148. GRPAND1 XOR A
  1149.         LD L,D
  1150.         LD (HL),A
  1151.         POP HL
  1152.         DJNZ GRPAND0
  1153.         JP _print
  1154.  
  1155. GRPOR   LD B,(HL)
  1156.         DEC B
  1157.         INC HL
  1158.         LD D,(HL)
  1159.         INC HL
  1160. GRPOR0 LD E,(HL)
  1161.         INC HL
  1162.         PUSH HL
  1163.         LD H,HIGH LOCVARS
  1164.         LD L,D
  1165.         LD A,(HL)
  1166.         CP 1
  1167.         JP P,GRPOR2
  1168.         LD L,E
  1169.         LD A,(HL)
  1170.         CP 1
  1171.         JP P,GRPOR2
  1172.         XOR A
  1173.         JR GRPOR1
  1174. GRPOR2  LD A,1
  1175. GRPOR1  LD L,D
  1176.         LD (HL),A
  1177.         POP HL
  1178.         DJNZ GRPOR0
  1179.         JP _print
  1180.  
  1181. TRUECONT LD E,(HL)
  1182.          LD D,HIGH LOCVARS
  1183.          LD A,(DE)
  1184.          AND A
  1185.          JP Z,ENDTEXT
  1186. ;        CP 1
  1187. ;        JP M,ENDTEXT
  1188.          INC HL
  1189.          JP _print
  1190.  
  1191. GOTO    LD A,(HL)
  1192.         INC HL
  1193.         LD H,(HL)
  1194.         LD L,A
  1195.         LD A,#40
  1196.         ADD A,H
  1197.         LD H,A
  1198.         JP _print
  1199.  
  1200. ISPOSITIVEGOTO:
  1201.         LD E,(HL)
  1202.         LD D,HIGH LOCVARS
  1203.         INC HL
  1204.         LD C,(HL)
  1205.         INC HL
  1206.         LD B,(HL)
  1207.         INC HL
  1208.         LD A,(DE)
  1209.         CP 1
  1210.         JP M,_print      ;A={0 FALSE
  1211.         LD A,#40        ;A}0 TRUE
  1212.         ADD A,B
  1213.         LD  H,A
  1214.         LD L,C
  1215.         JP _print
  1216.  
  1217. ISZEROGOTO:
  1218.         LD E,(HL)
  1219.         LD D,HIGH LOCVARS
  1220.         INC HL
  1221.         LD C,(HL)
  1222.         INC HL
  1223.         LD B,(HL)
  1224.         INC HL
  1225.         LD A,(DE)
  1226.         AND A
  1227.         JP NZ,_print ;A{}0
  1228.         LD A,#40        ;A=0
  1229.         ADD A,B
  1230.         LD  H,A
  1231.         LD L,C
  1232.         JP _print
  1233.  
  1234. ISNEGATIVEGOTO:
  1235.          LD E,(HL)
  1236.         LD D,HIGH LOCVARS
  1237.         INC HL
  1238.         LD C,(HL)
  1239.         INC HL
  1240.         LD B,(HL)
  1241.         INC HL
  1242.         LD A,(DE)
  1243.         AND A
  1244.         JP P,_print      ;}=0
  1245.         LD A,#40    ;{0
  1246.         ADD A,B
  1247.         LD  H,A
  1248.         LD L,C
  1249.         JP _print
  1250.  
  1251. ISNOTZEROGOTO:
  1252.         LD E,(HL)
  1253.         LD D,HIGH LOCVARS
  1254.         INC HL
  1255.         LD C,(HL)
  1256.         INC HL
  1257.         LD B,(HL)
  1258.         INC HL
  1259.         LD A,(DE)
  1260.         and a
  1261.         JP z,_print      ;A={0 FALSE
  1262.         LD A,#40        ;A}0 TRUE
  1263.         ADD A,B
  1264.         LD  H,A
  1265.         LD L,C
  1266.         JP _print
  1267.  
  1268. EXPANDGOTO
  1269.         LD E,(HL)
  1270.         LD D,HIGH LOCVARS
  1271.         LD A,(DE)
  1272.         ADD A,A
  1273.         INC HL
  1274.         LD D,0
  1275.         LD E,A
  1276.         ADD HL,DE
  1277.         LD C,(HL)
  1278.         INC HL
  1279.         LD B,(HL)
  1280.         EX DE,HL
  1281.         LD A,#40
  1282.         ADD A,B
  1283.         LD H,A
  1284.         LD L,C
  1285.  
  1286. EXP_GT1 INC DE
  1287.         LD A,(DE)
  1288.         CP #FF
  1289.         JR NZ,EXP_GT1
  1290.         INC DE
  1291.         LD A,(DE)
  1292.         CP #FF
  1293.         JR NZ,EXP_GT1
  1294.         INC DE
  1295.         ;ex de,hl
  1296.         LD (RETURN+1),DE
  1297.         LD A,#37
  1298.         LD (SUBLOCK),A
  1299.         JP _print
  1300.  
  1301. RANDOMIZE
  1302.         LD E,(HL)
  1303.         INC HL
  1304.         LD D,(HL)
  1305.         INC HL
  1306.         PUSH HL
  1307.         call randr
  1308.         LD D,HIGH LOCVARS
  1309.         LD (DE),A
  1310.         POP HL
  1311.         JP _print
  1312. randr:
  1313. SEED    LD HL,26356
  1314.         LD B,H
  1315.         ld C,L
  1316.         DB "))))"
  1317.         ADD HL,BC
  1318.         LD BC,20981
  1319.         ADD HL,BC
  1320.         LD (SEED+1),HL
  1321.         LD A,H
  1322.         ADD A,D
  1323.         JR NC,$-1
  1324.         ret
  1325. ;-------------------------------------
  1326. MENUOFF LD A,(HL)
  1327.         DEC A
  1328.         INC HL
  1329.         PUSH HL
  1330.         LD H,HIGH ACTMENU
  1331.         RLCA
  1332.         RLCA
  1333.         RLCA
  1334.         RLCA
  1335.         LD L,A
  1336.         XOR A
  1337.         LD (g_curpos),A
  1338.         LD (g_curpos+1),A
  1339.         INC A
  1340.         LD (HL),A
  1341.         POP HL
  1342.         JP _print
  1343.  
  1344. MENUON  LD A,(HL)
  1345.         DEC A
  1346.         INC HL
  1347.         PUSH HL
  1348.         LD H,HIGH ACTMENU
  1349.         RLCA
  1350.         RLCA
  1351.         RLCA
  1352.         RLCA
  1353.         LD L,A
  1354.         XOR A
  1355.         LD (HL),A
  1356.         LD (g_curpos),A
  1357.         LD (g_curpos+1),A
  1358.         POP HL
  1359.         JP _print
  1360.  
  1361. SUBMENUOFF
  1362.         LD A,(HL)
  1363.         DEC A   ;;;
  1364.         INC HL
  1365.         LD B,(HL)
  1366.         INC HL
  1367.         PUSH HL
  1368.         LD H,HIGH ACTMENU
  1369.         RLCA
  1370.         RLCA
  1371.         RLCA
  1372.         RLCA
  1373.         OR B
  1374.         LD L,A
  1375.         XOR A
  1376.         LD (g_curpos+1),A
  1377.         INC A
  1378.         LD (HL),A
  1379.         POP HL
  1380.         JP _print
  1381.  
  1382. SUBMENUON
  1383.         LD A,(HL)
  1384.         DEC A   ;;;;;;
  1385.         INC HL
  1386.         LD B,(HL)
  1387.         INC HL
  1388.         PUSH HL
  1389.         LD H,HIGH ACTMENU
  1390.         RLCA
  1391.         RLCA
  1392.         RLCA
  1393.         RLCA
  1394.         OR B
  1395.         LD L,A
  1396.         XOR A
  1397.         LD (HL),A
  1398.         POP HL
  1399.         LD (g_curpos+1),A
  1400.         JP _print
  1401.  
  1402.  
  1403.  
  1404. ;-----CLR GLOB VARS----
  1405. CLRVARS  LD B,(HL)
  1406.          XOR A
  1407.          INC HL
  1408. CLRVARS1 LD E,(HL)
  1409.          LD D,HIGH GLOBVARS
  1410.          LD (DE),A
  1411.          INC HL
  1412.          DJNZ CLRVARS1
  1413.         JP _print
  1414. ;--------------------------
  1415. ;==========================
  1416. _menu:
  1417.         ;clear stk_menu
  1418.         ld hl,STK_MENU
  1419.         ld de,STK_MENU+1
  1420.         ld bc,355
  1421.         ld (hl),0xff
  1422.         ldir
  1423.  
  1424.         ld hl,ACTMENU
  1425.         ld (ACTTMP),hl ;
  1426.         ld hl,STK_MENU
  1427.         ld (STK_MTMP),hl
  1428.         xor a
  1429.         ld (COUNTER),a ;....
  1430.         ld hl,0x1300
  1431.         ld (g_atpos),hl   ;...
  1432.  
  1433.         ld hl,0x4006 ; pic pointer (limiter)
  1434.  
  1435.         ld a,(hl)
  1436.         ld (LIMIT1),a ;low  
  1437.  
  1438.         inc hl
  1439.         ld a,(hl)
  1440.         ld b,0x40
  1441.         add a,b
  1442.         ld (LIMIT2),a ;high
  1443.  
  1444.         ld hl,0x4004 ;tree pointer
  1445.         ld b,(hl)
  1446.         inc hl
  1447.         ld h,(hl)
  1448.         ld a,0x40
  1449.         add a,h
  1450.         ld h,a
  1451.         ld l,b ;hl pointer to tree root
  1452. _menu1:
  1453.         ld a,0
  1454. LIMIT2 equ $-1
  1455.         cp h
  1456.         jr nz,_menu2
  1457.         ld a,0
  1458. LIMIT1  equ $-1
  1459.         cp l
  1460.         jp z,SELECTOR ; end of tree
  1461. _menu2:
  1462.         ld e,(hl)
  1463.         inc hl
  1464.         ld d,(hl)
  1465.         inc hl
  1466.         ld a,d
  1467.         or e
  1468.         jp z,SELECTOR ;no menu tree
  1469.  
  1470.         push hl
  1471.         ld bc,0
  1472. ACTTMP  equ $-2
  1473.  
  1474.         LD A,(BC)
  1475.         LD B,A
  1476.         LD  A,C
  1477.         ADD A,16
  1478.         LD (ACTTMP),A
  1479.         LD A,B
  1480.         AND A
  1481.         JP NZ,_menu5     ;NOT ACTIVE
  1482.         LD A,#40
  1483.         ADD A,D
  1484.         LD D,A
  1485.         LD HL,0
  1486. STK_MTMP EQU $-2
  1487.         LD A,(COUNTER)
  1488.         LD (HL),A
  1489.         INC HL
  1490.         LD (HL),E
  1491.         INC HL
  1492.         LD (HL),D
  1493.         INC HL
  1494.         LD (STK_MTMP),HL ;
  1495.         LD (HL),#FF
  1496.         EX DE,HL
  1497.         LD E,(HL)
  1498.         INC HL
  1499.         LD D,(HL)
  1500.         LD A,#40
  1501.         ADD A,D
  1502.         LD D,A
  1503.         INC DE ;SKIP MENUNAME NUM
  1504.         EX DE,HL
  1505.  
  1506. ;---╨┐╨╡╤З╨░╤В╤М ╨╜╨░╨╖╨▓╨░╨╜╨╕╤П ╨╝╨╡╨╜╤О--
  1507.  
  1508.         LD BC,(g_atpos)
  1509.         CALL _pradd
  1510.  
  1511. _menu3:
  1512.         LD A,(HL)
  1513.         INC HL
  1514.         AND A
  1515.         JR Z,_menu4
  1516.         CP 128
  1517.         CALL NC,change_cp        
  1518.         SUB 32
  1519.         PUSH HL
  1520.         CALL _type
  1521.         POP HL
  1522.         JR _menu3
  1523.  
  1524. _menu4:
  1525.         LD A,(g_atpos) ;x-coord
  1526.         add a,16
  1527.         ld (g_atpos),a
  1528.         cp 64
  1529.         jr c,_menu5
  1530.  
  1531.         and 0x3f
  1532.         LD (g_atpos),A
  1533.  
  1534.         ld a,(g_atpos+1)
  1535.         inc a
  1536.         ld (g_atpos+1),a
  1537. _menu5
  1538.         LD A,0
  1539. COUNTER EQU $-1
  1540.         INC A
  1541.         LD (COUNTER),A
  1542.         POP HL
  1543.         JP _menu1
  1544.  
  1545. SELECTOR:
  1546.         ld a,8
  1547.         ld (_line_lenght),a
  1548.  
  1549.         LD DE,STK_MENU
  1550.         LD A,(g_curpos)
  1551.         LD L,A
  1552.         ADD A,A
  1553.         ADD A,L
  1554.         LD L,A
  1555.         LD H,0
  1556.         ADD HL,DE
  1557.         EX DE,HL
  1558.  
  1559. SELS0:
  1560.         ld a,(g_curpos)
  1561.         ld hl,MENUCURHELPER
  1562.         call sel_word
  1563.         ld (SELS4),hl
  1564.  
  1565.         call _highlight_selected
  1566. SELS3:
  1567.         call waitkey
  1568.  
  1569.  
  1570.  
  1571.         cp key_esc
  1572.         jp z,TO_MENU
  1573.  
  1574.         cp key_left
  1575.         jp z,SELS_keyleft
  1576.         cp key_right
  1577.         jp z,SELS_keyright
  1578.  
  1579.  
  1580.         cp key_up
  1581.         jp z,SELS_keyup
  1582.         cp key_down
  1583.         jp z,SELS_keydown
  1584.  
  1585.  
  1586.         cp key_enter
  1587.         jp z,SELECTED1
  1588.         cp ' '
  1589.         jp z,SELECTED1
  1590.         jr SELS3        
  1591.  
  1592.  
  1593. SELS_keyup:
  1594. ;        ;de - modified pos in stk_menu
  1595. ;
  1596.         push de        
  1597.         pop hl
  1598.  
  1599.         ld bc,0xfff4 ;(-12)
  1600.         add hl,bc
  1601.         ld bc,STK_MENU
  1602.         and a
  1603.         sbc hl,bc
  1604. ;        ld  a,h
  1605. ;        or l
  1606. ;        jr z,SELS_keyup_c
  1607.         jp m,SELS3
  1608. ;SELS_keyup_c:
  1609.         ex de,hl
  1610.         ld bc,-12
  1611.         add hl,bc
  1612.         ex de,hl
  1613.  
  1614.  
  1615.         ld hl,(SELS4)
  1616.         call _highlight_selected
  1617.         ld a,(g_curpos)
  1618.         add a,-4
  1619.         ld (g_curpos),a
  1620.         xor a
  1621.         ld (g_curpos+1),a
  1622.         jp SELS0
  1623.  
  1624.  
  1625. SELS_keydown:
  1626.         ;de - modified pos in stk_menu
  1627.         push de
  1628.         pop hl
  1629.         ld bc,12
  1630.         add hl,bc
  1631.         ld a,(hl)
  1632.         inc a
  1633.         jr  z,SELS3
  1634.         ex de,hl
  1635.  
  1636.         ld a,(g_curpos)
  1637.         add a,4
  1638.         ld (g_curpos),a        
  1639.         ld hl,(SELS4)
  1640.         call _highlight_selected
  1641.         xor a
  1642.         ld (g_curpos+1),a        
  1643.         jp SELS0  
  1644.  
  1645. SELS_keyleft:
  1646.         push de        
  1647.         pop hl
  1648.         ld bc,STK_MENU
  1649.         and a
  1650.         SBC HL,BC
  1651.         ld  a,h
  1652.         or l
  1653.         jr z,SELS3
  1654.  
  1655.         ex de,hl
  1656.         ld bc,3
  1657.         and a
  1658.         sbc hl,bc
  1659.         ex de,hl
  1660.  
  1661.         ld hl,(SELS4)
  1662.         call _highlight_selected
  1663.         ld hl,g_curpos
  1664.         dec (hl)
  1665.         xor a
  1666.         ld (g_curpos+1),a
  1667.         jp SELS0
  1668. SELS_keyright:
  1669.         push de
  1670.         pop hl
  1671.         ld bc,3
  1672.         add hl,bc
  1673.         ld a,(hl)
  1674.         inc a
  1675.         jp  z,SELS3
  1676.         ex de,hl
  1677.  
  1678.         ld hl,g_curpos
  1679.         inc (hl)        
  1680.         ld hl,0
  1681. SELS4   equ $-2
  1682.         call _highlight_selected
  1683.         xor a
  1684.         ld (g_curpos+1),a        
  1685.         jp SELS0  
  1686.      
  1687. SELECTED1:
  1688.         push de
  1689.         call WINCLR2
  1690.         ld hl,ACTMENU
  1691.         ld (ACTTMP1),hl
  1692.         xor a
  1693.         ld (COUNTER),a
  1694.  
  1695.         ;clear stk_sub
  1696.         ld hl,STK_SUB
  1697.         ld de,STK_SUB+1
  1698.         ld bc,355
  1699.         ld (hl),0xff
  1700.         ldir
  1701.  
  1702.         LD HL,STK_SUB
  1703.         LD (STK_STMP),HL
  1704.         LD HL,#1300
  1705.         LD (g_atpos),HL        
  1706.         POP DE
  1707.         LD A,(DE)
  1708.         LD (RESULT),A;╤Б╨╛╤Е╤А╨░╨╜╤П╨╡╨╝ ╨╜╨╛╨╝╨╡╤А ╨▓╤Л╨▒╤А╨░╨╜╨╜╨╛╨│╨╛ ╨╝╨╡╨╜╤О
  1709.         RLCA
  1710.         RLCA
  1711.         RLCA
  1712.         RLCA
  1713.         INC A
  1714.         LD (ACTTMP1),A
  1715.         INC DE
  1716.         LD A,(DE)
  1717.         LD L,A
  1718.         INC DE
  1719.         LD A,(DE)
  1720.         LD H,A
  1721.         INC HL,HL
  1722.         ;HL-TREE          SUBMENU NAMES
  1723. SMENU1:
  1724.         LD E,(HL)
  1725.         INC HL
  1726.         LD D,(HL)
  1727.         INC HL,DE
  1728.         LD A,D
  1729.         OR E
  1730.         JP Z,SELECTOR2
  1731.         DEC DE
  1732.         PUSH HL
  1733.         LD BC,0
  1734. ACTTMP1 EQU $-2
  1735.  
  1736.         LD A,(BC)
  1737.         LD B,A
  1738.         LD  A,C
  1739.         INC A
  1740.         LD (ACTTMP1),A
  1741.         LD A,B
  1742.         AND A
  1743.         JP NZ,SMENU5    ;IF NOT ACTIVE
  1744.         LD A,0x40
  1745.         ADD A,D
  1746.         LD D,A
  1747. ;DE - ADR OF SUBMENU NAME1              ;
  1748.         LD HL,0                         ;
  1749. STK_STMP EQU $-2                        ;
  1750.         LD A,(COUNTER)                  ;
  1751.         LD (HL),A                       ;
  1752.         INC HL                          ;
  1753.         LD (STK_STMP),HL ;              ;
  1754.         LD (HL),#FF                     ;
  1755.  
  1756.         INC DE ;SKIP MENUNAME NUMBER
  1757.         EX DE,HL        
  1758. ;HL-NAME OF MENUITEM
  1759.  
  1760. ;---╨┐╨╡╤З╨░╤В╤М ╨╜╨░╨╖╨▓╨░╨╜╨╕╤П ╨╝╨╡╨╜╤О--
  1761.  
  1762.         LD BC,(g_atpos)
  1763.         CALL _pradd
  1764.  
  1765. SMENU3
  1766.         LD A,(HL)
  1767.         INC HL
  1768.         AND A
  1769.         JR Z,SMENU4
  1770.         CP 128
  1771.         CALL NC,change_cp        
  1772.         SUB 32
  1773.         PUSH HL
  1774.         CALL _type
  1775.         POP HL
  1776.         JR SMENU3
  1777.  
  1778. SMENU4:
  1779.         LD A,(g_atpos) ;x-coord
  1780.         add a,16
  1781.         ld (g_atpos),a
  1782.         cp 64
  1783.         jr c,SMENU5
  1784.  
  1785.         and 0x3f
  1786.         LD (g_atpos),A
  1787.  
  1788.         ld a,(g_atpos+1)
  1789.         inc a
  1790.         ld (g_atpos+1),a
  1791.  
  1792. SMENU5  LD HL,COUNTER
  1793.         INC (HL)
  1794.         POP HL
  1795.         JP SMENU1
  1796.  
  1797. SELECTOR2:
  1798.         ld hl,(STK_STMP)
  1799.         ld de,STK_SUB
  1800.         and a
  1801.         sbc hl,de
  1802.         ld a,h
  1803.         or l
  1804.         jp z,RESULT1
  1805.         ld a,(g_curpos+1)
  1806.         ld l,a
  1807.         ld h,0
  1808.         add hl,de
  1809.         ex de,hl
  1810.  
  1811. SSELS0:
  1812.         ld a,(g_curpos+1)
  1813.         ld hl,MENUCURHELPER
  1814.         call sel_word
  1815. SSELS2:        
  1816.         ld (SSELS4),hl
  1817.         call _highlight_selected
  1818. SSELS3:
  1819.         call waitkey
  1820. ;        cp key_up
  1821. ;        jr z,SELS_keyup
  1822. ;        cp key_down
  1823. ;        jr z,SELS_keydown
  1824.         cp key_esc
  1825.         jp z,SSELLL
  1826.  
  1827.  
  1828.         cp key_left
  1829.         jr z,SSELS_keyleft
  1830.         cp key_right
  1831.         jr z,SSELS_keyright
  1832.  
  1833.  
  1834.         cp key_up
  1835.         jr z,SSELS_keyup
  1836.         cp key_down
  1837.         jr z,SSELS_keydown
  1838.  
  1839.         cp key_enter
  1840.         jr z,SELECTED
  1841.         cp ' '
  1842.         jr z,SELECTED
  1843.         jr SSELS3        
  1844.  
  1845.  
  1846. SSELS_keyup:
  1847.         push de        
  1848.         pop hl
  1849.        
  1850.         ld bc,-4 ;-1
  1851.         add hl,bc
  1852.         ld bc,STK_SUB
  1853.         and a
  1854.         SBC HL,BC
  1855.         jp m,SSELS3
  1856.  
  1857.         ex de,hl
  1858.         ld bc,-4
  1859.         add hl,bc
  1860.         ex de,hl
  1861.  
  1862.         ld hl,(SSELS4)
  1863.         call _highlight_selected
  1864.         ld a,(g_curpos+1)
  1865.         add a,-4
  1866.         ld (g_curpos+1),a
  1867.         jp SSELS0
  1868.  
  1869.  
  1870.  
  1871.  
  1872. SSELS_keydown:
  1873.         push de
  1874.         pop hl
  1875.        
  1876.         ld bc,4
  1877.         add hl,bc
  1878.  
  1879.         ld a,(hl)
  1880.         inc a
  1881.         jr  z,SSELS3
  1882.         ex de,hl
  1883.  
  1884.         ld a,(g_curpos+1)
  1885.         add a,4
  1886.         ld (g_curpos+1),a
  1887.         ld hl,(SSELS4)
  1888.         call _highlight_selected
  1889.         jp SSELS0  
  1890.  
  1891.  
  1892.  
  1893.  
  1894. SSELS_keyleft:
  1895.         push de        
  1896.         pop hl
  1897.         ld bc,STK_SUB
  1898.         and a
  1899.         SBC HL,BC
  1900.         ld  a,h
  1901.         or l
  1902.         jr z,SSELS3
  1903.         dec de
  1904.         ld hl,(SSELS4)
  1905.         call _highlight_selected
  1906.         ld hl,g_curpos+1
  1907.         dec (hl)
  1908.         jp SSELS0
  1909. SSELS_keyright:
  1910.         push de
  1911.         pop hl
  1912.         inc hl
  1913.         ld a,(hl)
  1914.         inc a
  1915.         jp  z,SSELS3
  1916.         ex de,hl
  1917.         ld hl,g_curpos+1
  1918.         inc (hl)        
  1919.         ld hl,0
  1920. SSELS4   equ $-2
  1921.         call _highlight_selected
  1922.         jp SSELS0  
  1923. SELECTED:
  1924.         LD A,(DE)
  1925.         LD H,A
  1926.         PUSH HL
  1927.         LD HL,(SSELS4)
  1928.         CALL _highlight_selected
  1929.         POP HL
  1930. RESSULT   LD L,0
  1931. RESULT  EQU $-1
  1932. ;L-MENU NUM H-SUBMENUNUM
  1933.         INC H
  1934.         INC L
  1935.         RET
  1936. RESULT1 LD H,#FF
  1937.         JR RESSULT
  1938. SSELLL:
  1939.         pop hl
  1940.         jp TXTOUT1
  1941. ;---------------------------------
  1942. ;╨╖╨░╨│╨╗╤Г╤И╨║╨╕
  1943. EXITLIGHT
  1944.         LD B,250
  1945.         HALT
  1946.         DJNZ $-1
  1947.  
  1948.        call fade_towhite
  1949. ;       CALL clear_whole_screen
  1950.        JP begin
  1951. ;        LD B,250
  1952. ;        HALT
  1953. ;        DJNZ $-1
  1954. ;
  1955.  ;       CALL clear_whole_screen
  1956. ;prebegin        
  1957. ;
  1958. ;        ld hl,endingovl
  1959. ;        jp LOADOVL
  1960.  
  1961.  
  1962. ;---------------------------
  1963. EXITDARK
  1964. ;        LD B,250
  1965. ;        HALT
  1966. ;        DJNZ $-1
  1967.  
  1968.        call fade_toblack
  1969.        CALL clear_whole_screen
  1970.        JP begin
  1971.  
  1972. ;;;;;;;;;;;;;;;;;;;;;;;;;;        
  1973. TO_MENU:
  1974.         pop hl
  1975.  
  1976.         ld a,2
  1977.         ld (_ingame_m_downlimit),a
  1978.  
  1979.         ld hl,loc_m1_menu
  1980.         ld de,menu_m1_action
  1981.         jr _ingame_menu_mnu
  1982.  
  1983. _ingame_menu_mnu:
  1984.  
  1985.         push hl
  1986.         push de
  1987.  
  1988.         ld hl,TABLE_W
  1989.         ld (CODEPAGE),hl
  1990.        
  1991.         CALL WINCLR2
  1992.  
  1993.  
  1994.         LD HL,#1300
  1995.         LD (_ingame_m_mnpos),HL
  1996.  
  1997.         xor a
  1998.         ld (_ingame_m_curpos),a
  1999.  
  2000.         pop de
  2001.         pop hl
  2002.  
  2003.         push de
  2004.         ld a,(language)
  2005.         call sel_word
  2006.  
  2007.         call _prt_ingame_menu
  2008.  
  2009.         call _sel_ingame_menu
  2010.  
  2011.         pop hl
  2012.  
  2013.         cp 0xff
  2014.         jp z,TO_MENU_ESC
  2015.         call sel_word
  2016.         jp (hl)
  2017. TO_MENU_ESC
  2018.        ; pop hl ; ;;??????
  2019.         ld hl,TABLE_J
  2020.         ld (CODEPAGE),hl      
  2021.         jp TXTOUT1
  2022.  
  2023.  
  2024. _confirm_quit:
  2025.         ld a,1
  2026.         ld (_ingame_m_downlimit),a
  2027.  
  2028.         ld  hl,loc_m2_menu
  2029.         ld  de,menu_m2_action
  2030.         jp _ingame_menu_mnu
  2031. _ram_save:
  2032.         ld a,4
  2033.         ld (_ingame_m_downlimit),a
  2034.  
  2035.         ld  hl,loc_save_menu_ingame
  2036.         ld  de,loc_save_menu_ingame_action
  2037.         jp _ingame_menu_mnu
  2038. _ram_load:
  2039.         ld a,4
  2040.         ld (_ingame_m_downlimit),a
  2041.        
  2042.         ld  hl,loc_load_menu_ingame
  2043.         ld  de,loc_load_menu_ingame_action
  2044.         jp _ingame_menu_mnu
  2045.  
  2046. _save_slot_1:
  2047.         ld a,1
  2048.         jr _save_slot
  2049. _save_slot_2:
  2050.         ld a,2
  2051.         jr _save_slot
  2052. _save_slot_3:
  2053.         ld a,3
  2054.         jr _save_slot
  2055. _save_slot_4:
  2056.         ld a,4
  2057.         jr _save_slot
  2058. _save_slot_5:
  2059.         ld a,5
  2060. _save_slot:
  2061.         add a,"0"
  2062.         ld (SAVETEMPL_N),a
  2063.  
  2064. _retry_save:
  2065.         ld de,SAVETEMPL
  2066.         call openstream_file
  2067.         or a
  2068.         jp z,_save_slot_is_present
  2069.         ; we should create file here
  2070.  
  2071.          LD DE,SAVETEMPL
  2072.          OS_CREATEHANDLE
  2073.          OR A
  2074.          JP NZ,filecreateeerror
  2075.          ld a,b
  2076.          ld (filehandle),a
  2077.  
  2078.  
  2079.  
  2080.  
  2081. _save_slot_is_present:
  2082.         ld hl,buf
  2083.         ld de,buf+1
  2084.         ld bc,537
  2085.         ld (hl),0
  2086.         ldir            ;clear buffer
  2087.  
  2088.         call globals_to_save
  2089.  
  2090.         ld hl,538 ;len
  2091.         ld de,buf ;addr
  2092.         call savestream_file
  2093.         or a
  2094.         jp nz,filewriteerror
  2095.  
  2096.         call closestream_file        
  2097.         jp TO_MENU_ESC
  2098.  
  2099.  
  2100.  
  2101. _load_slot_1:
  2102.         ld a,1
  2103.         jr _load_slot_o
  2104. _load_slot_2:
  2105.         ld a,2
  2106.         jr _load_slot_o
  2107. _load_slot_3:
  2108.         ld a,3
  2109.         jr _load_slot_o
  2110. _load_slot_4:
  2111.         ld a,4
  2112.         jr _load_slot_o
  2113. _load_slot_5:
  2114.         ld a,5
  2115. _load_slot_o:
  2116.         add a,"0"
  2117.         ld (SAVETEMPL_N),a
  2118.  
  2119.         ld de,SAVETEMPL
  2120.         call openstream_file
  2121.         or a
  2122.         jp nz,TO_MENU_ESC
  2123.  
  2124.         call disable_anim
  2125.  
  2126.         jp _load_common
  2127.  
  2128.  
  2129. outtype2 db 0   ;"P' Єоб╖сма я╕ис│╝. 'N' тжз я╕иЄ│ли  '8' Є░▒аъ░Н
  2130.  
  2131. ;;;;
  2132. SHOWSCR
  2133.  
  2134.         call disable_anim
  2135.  
  2136.         ld a,(hl)
  2137.         inc hl
  2138.         push hl
  2139.         call _get_show_scr
  2140.         pop hl
  2141.         jp _print
  2142.  
  2143. _get_show_scr:
  2144.         push af
  2145.  
  2146.         ld a,(script_buf1)
  2147.         SETPG4000
  2148.         ld a,(script_buf2)              
  2149.         SETPG8000        
  2150.  
  2151.         ld hl,(0x4006)
  2152.         ld a,h
  2153.         add a,0x40
  2154.         ld h,a
  2155.        
  2156.         pop af
  2157.         call sel_word
  2158.         ld a,h
  2159.         add a,0x40
  2160.         ld h,a      
  2161.  
  2162.         ld a,(hl)
  2163.         ld (outtyp),a
  2164.         inc hl
  2165.         ld a,(hl)
  2166.         ld (outtype2),a
  2167.         inc hl
  2168.  
  2169.  
  2170.  
  2171.  
  2172.         ld a,(outtype2)
  2173.  
  2174.         cp '8'
  2175.         jp z,_it_is_overlay
  2176.  
  2177.         cp 'P'
  2178.         jp z,_clear_screen_before
  2179.  
  2180. _show_screen_immedatelly:
  2181.  
  2182.         call load_gfx_to_load_buf
  2183.  
  2184.         jp _buffer_output        
  2185. outtyp_conv: db 0,10,10,10,4,5,6,12,13,0,10,11
  2186. _clear_screen_before:
  2187.         push hl
  2188.         ld a,(outtyp)
  2189.         push af
  2190.  
  2191.         ld e,a
  2192.         ld d,0
  2193.         ld hl, outtyp_conv
  2194.         add hl,de
  2195.         ld a,(hl)
  2196.         ld (outtyp),a
  2197.  
  2198.         ld hl,pal
  2199.         ld de,mempal
  2200.         ld bc,32
  2201.          ldir
  2202.  
  2203.  
  2204.         call _memory_output
  2205.  
  2206.     ;    ld hl,temppal
  2207.      ;   ld de,pal
  2208.       ;  ld bc,32
  2209.        ; ldir
  2210.  
  2211.         pop af
  2212.         ld (outtyp),a
  2213.         pop hl
  2214.         jp _show_screen_immedatelly
  2215.  
  2216. _it_is_overlay:
  2217.         call store_name
  2218.  
  2219.  
  2220.         call load_gfx_to_scr_buf
  2221.  
  2222.         call _sprite_output_mask_no_pal
  2223.  
  2224.  
  2225.         call load_eyes
  2226.  
  2227.         ld a,1
  2228.         ld (alock),a
  2229.         ret
  2230.  
  2231. SHOWDOUBLESCR:
  2232.  
  2233.                 call disable_anim
  2234.  
  2235.                 ld a,(script_buf1)
  2236.                 SETPG4000
  2237.                 ld a,(script_buf2)              
  2238.                 SETPG8000        
  2239.  
  2240.         LD      E,(HL)
  2241.         INC     HL
  2242.         INC     HL
  2243.         LD      D,(HL)
  2244.         INC     HL
  2245.         PUSH    HL    
  2246.  
  2247.  
  2248.             push de
  2249.             ld a,d
  2250.  
  2251.                 push af      
  2252.                 ld hl,(0x4006)
  2253.                 ld a,h
  2254.                 add a,0x40
  2255.                 ld h,a      
  2256.                 pop af
  2257.  
  2258.                 call sel_word
  2259.                 ld a,h
  2260.                 add a,0x40
  2261.                 ld h,a      
  2262.        
  2263.                 ld a,(hl)
  2264.                 ld (outtyp),a
  2265.                 inc hl
  2266.                 ld a,(hl)
  2267.                 ld (outtype2),a
  2268.                 inc hl
  2269.  
  2270.                 ld a,(outtype2)        
  2271.                 cp '8'
  2272.                 jp z,_second_is_overlay
  2273.  
  2274.  
  2275.                 call load_gfx_to_load_buf
  2276.                 xor a
  2277.                 ld (mask_mode),a
  2278.                 jr _sds_second_image
  2279.  
  2280. _second_is_overlay:
  2281.                 ld a,1
  2282.                 ld (mask_mode),a
  2283. ;load tb_008                
  2284.                 push hl
  2285.                 ld hl,tb008
  2286.                  call load_gfx_to_load_buf_nopal
  2287.                 pop hl
  2288. ;load sprite to scr_buf
  2289.  
  2290.                 call store_name
  2291.  
  2292.                 call load_gfx_to_scr_buf
  2293.                 CALL DECR_SPR
  2294.  
  2295.                 call load_eyes
  2296.  
  2297. _sds_second_image:
  2298.         pop de
  2299.         ld a,e
  2300.                 push af      
  2301.                 ld hl,(0x4006)
  2302.                 ld a,h
  2303.                 add a,0x40
  2304.                 ld h,a      
  2305.                 pop af
  2306.  
  2307.                 call sel_word
  2308.                 ld a,h
  2309.                 add a,0x40
  2310.                 ld h,a
  2311.                 inc hl
  2312.                 inc hl
  2313.  
  2314.                 call store_name
  2315.  
  2316.                 call load_gfx_to_scr_buf
  2317.                 CALL DECR_SPR
  2318.  
  2319.                 call load_eyes
  2320.  
  2321.                 call _buffer_output_op
  2322.  
  2323.                 ld a,1
  2324.                 ld (alock),a
  2325.  
  2326.         pop hl
  2327.         jp _print
  2328. ;==============================================================        
  2329. disable_anim:
  2330.         push af
  2331.         push hl
  2332.         push bc
  2333.  
  2334.         ;swith off animations
  2335.         xor a
  2336.         ld (alock),a
  2337.         ld (anim_stack_spr_num),a
  2338.  
  2339.         ;clear animations stack
  2340.         ld b,0
  2341. 1       ld hl,anim_stack
  2342.         ld (hl),a
  2343.         inc hl
  2344.         djnz 1b
  2345.  
  2346.         ld hl,anim_stack
  2347.         ld (anim_stack_cursor),hl
  2348.  
  2349.         pop bc
  2350.         pop hl
  2351.         pop af
  2352.         ret  
  2353.  
  2354.  
  2355.  
  2356. store_name:
  2357.         push hl
  2358.         ld hl,namebuf
  2359.         ld de,namebuf+1
  2360.         ld bc,13
  2361.         ld (hl),0
  2362.         ldir
  2363.         pop hl
  2364.         push hl
  2365.         ld de,namebuf
  2366.         call copystr_hlde
  2367.         pop hl
  2368.         ret        
  2369.  
  2370. load_eyes:
  2371.     ;ret
  2372.         push hl
  2373.         push bc
  2374.         push de
  2375.         push af
  2376.  
  2377.  
  2378.         ;namebuf
  2379.         ;eyes_table:
  2380.         ld hl,eyes_table
  2381.  
  2382. load_eyes_main_loop:
  2383.         ld de,namebuf
  2384.         ld a,(hl)
  2385.         cp 0xff
  2386.         jp z,load_eyes_exit ;eof
  2387.  
  2388.  
  2389.         push hl
  2390.             call cmpr_dehl
  2391.             jp nz,load_eyes_skip_to_next
  2392.    
  2393.             call setfontpage
  2394.         pop hl
  2395.         push hl
  2396.             call load_anim_pre_sub
  2397.  
  2398.             ld a,(anim_stack_spr_num)
  2399.             add a,a
  2400.             ld d,a
  2401.             add a,a ;ax4
  2402.             add a,d ;ax6
  2403.             ld de,ANIM_BFF
  2404.             add a,d
  2405.             ld d,a
  2406.                 ;put sprite addr in anim stack
  2407.                 ld hl,(anim_stack_cursor)
  2408.                 ld (hl),e
  2409.                 inc hl
  2410.                 ld (hl),d
  2411.                 inc hl
  2412.                 ld (anim_stack_cursor),hl
  2413.  
  2414.             ;load animation to font page
  2415.             ld hl,0x8000
  2416.             call readstream_file
  2417.             or a
  2418.             jp nz,filereaderror
  2419.  
  2420.             call closestream_file
  2421.  
  2422.             call unsetfontpage
  2423.         pop hl
  2424.  
  2425.  
  2426.         ;skip name again
  2427.         ld de,buf
  2428.         call copystr_hlde
  2429.         inc hl
  2430.        
  2431.         ;get x
  2432.         ld e,(hl)
  2433.         inc hl
  2434.         ld d,(hl)
  2435.         inc hl
  2436.  
  2437.         ;x - to addr
  2438.         ex de,hl
  2439.         call p_calc_x
  2440.         ld bc,5 ;offscreen offset
  2441.         add hl,bc
  2442.         push hl
  2443.         ex de,hl
  2444.  
  2445.         ;get_y
  2446.         ld e,(hl)
  2447.         inc hl
  2448.         ld d,(hl)
  2449.         inc hl
  2450.         ld a,8  ;offscreen offset
  2451.         add a,e
  2452.  
  2453.  
  2454.         ;add y offset
  2455.         ex de,hl
  2456.         pop hl  
  2457.         call p_calc_y
  2458.  
  2459.  
  2460.         push hl
  2461.         pop bc
  2462.  
  2463.                 ;put sprite ega screen  addr in anim stack
  2464.                 ld hl,(anim_stack_cursor)
  2465.                 ld (hl),c
  2466.                 inc hl
  2467.                 ld (hl),b
  2468.                 inc hl
  2469.                 ld (anim_stack_cursor),hl        
  2470.  
  2471.         ex de,hl
  2472.  
  2473.         ld c,(hl)
  2474.         inc hl
  2475.         inc hl
  2476.         ld b,(hl)
  2477.         inc hl
  2478.         inc hl
  2479.  
  2480.         ex de,hl
  2481.         ld hl,(anim_stack_cursor)
  2482.         ld (hl),c ;len
  2483.         inc hl
  2484.         ld (hl),b ;hgt
  2485.         inc hl
  2486.         ld (anim_stack_cursor),hl        
  2487.         ex de,hl
  2488.  
  2489.         ld b,(hl) ;num phases
  2490.         inc hl
  2491.  
  2492.         ex de,hl
  2493.         ld hl,(anim_stack_cursor)
  2494.         ld (hl),b ; phases
  2495.         inc hl
  2496.         ld (hl),0xfe ;counter 1
  2497.         inc hl
  2498.         ld (hl),0        ;counter 2
  2499.         inc hl
  2500.         ld (hl),0     ;placeholders  
  2501.         inc hl        
  2502.         ld (hl),0        
  2503.         inc hl
  2504.         ld (hl),0        
  2505.         inc hl        
  2506.         ld (hl),0        
  2507.         inc hl        
  2508.         ld (hl),0        
  2509.         inc hl        
  2510.         ld (hl),0        
  2511.         inc hl        
  2512.         ld (hl),0        
  2513.         inc hl        
  2514.         ld (anim_stack_cursor),hl        
  2515.  
  2516.  
  2517.         ld hl,anim_stack_spr_num
  2518.         inc (hl)
  2519.  
  2520.         ex de,hl
  2521.  
  2522.         jp load_eyes_main_loop
  2523.         ;load gfx to buf by name
  2524.         ;move gfx to font_page
  2525.         ;setup animation stack
  2526.  
  2527.  
  2528. load_eyes_exit:
  2529. ;        ld a,1
  2530. ;        ld(alock),a
  2531.         pop af
  2532.         pop de
  2533.         pop bc
  2534.         pop hl
  2535.         ret
  2536. load_eyes_skip_to_next:
  2537.         pop hl
  2538.         ld bc,16
  2539.         add hl,bc
  2540.         jp load_eyes_main_loop
  2541.  
  2542.  
  2543. cmpr_dehl:
  2544.         ld a,(de)
  2545.         and a
  2546.         ret z   ;string fully equally and dtring in de not begin from 0
  2547.  
  2548.         cpi
  2549.         ret nz
  2550.         inc de
  2551.         jr cmpr_dehl
  2552.  
  2553. C_Time_D:
  2554. ;Outputs:
  2555. ;     A is the result
  2556. ;     B is 0
  2557.      ld b,8          ;7           7
  2558.      xor a           ;4           4
  2559.        rlca          ;4*8        32
  2560.        rlc c         ;8*8        64
  2561.        jr nc,$+3     ;(12|11)    96|88
  2562.          add a,d     ;--
  2563.        djnz $-6      ;13*7+8     99
  2564.      ret             ;10         10
  2565.  
  2566. ;___________________________________
  2567. ;A15    A14     A13     A12     A11     A10      A9      A8
  2568. ; G0     R0      B0      G1      1       1       R1      B1
  2569.                
  2570. ; D7     D6      D5      D4      D3      D2      D1      D0
  2571. ; G2     R2      B2      G3      1       1       R3      B3
  2572. palette_precalc:
  2573.                 push hl
  2574.                 push de
  2575.                 push bc
  2576.                 push af
  2577.  
  2578.                 ld b,6
  2579. _pal_pc_l1:
  2580.                 push bc
  2581.  
  2582.                 ld a,b
  2583.                 push af ;store fase
  2584.                 add a,a ;x2
  2585.                 add a,a ;x4
  2586.                 add a,a ;x8
  2587.                 add a,a ;x16
  2588.                 add a,a ;x32
  2589.                 ld e,a
  2590.                 ld d,high _pal_bright   ;adr palette
  2591.                 ld hl,pal ;source palette
  2592.  
  2593.                 pop af
  2594.                 call _pal_transfer
  2595.  
  2596.                 pop bc
  2597.                 djnz _pal_pc_l1
  2598.  
  2599.                 pop af
  2600.                 pop bc
  2601.                 pop de
  2602.                 pop hl
  2603.                 ret  
  2604.  
  2605. _pal_transfer:
  2606.                 cp 0
  2607.                 jp z,_pal_tsf_0
  2608.                 cp 1
  2609.                 jp z,_pal_tsf_1
  2610.                 cp 2
  2611.                 jp z,_pal_tsf_2
  2612.                 cp 3
  2613.                 jp z,_pal_tsf_3
  2614.                 cp 4
  2615.                 jp z,_pal_tsf_4
  2616.                 cp 5
  2617.                 jp z,_pal_tsf_5
  2618.                 cp 6
  2619.                 jp z,_pal_tsf_6
  2620.                 cp 7
  2621.                 jp z,_pal_tsf_7
  2622.  
  2623.  
  2624. _pal_tsf_3:
  2625.                 ld b,16
  2626. 1               ld a,(hl)
  2627.                 ld (de),a
  2628.                 inc hl
  2629.                 inc de
  2630.                 ld a,(hl)
  2631.                 or 0x1f ;b00011111
  2632.                 ld (de),a
  2633.                 inc de
  2634.                 inc hl
  2635.                 djnz 1b
  2636.                 ret
  2637.  
  2638. _pal_tsf_2:
  2639.                 ld b,16
  2640. 1               ld a,(hl)
  2641.                 ld (de),a
  2642.                 inc hl
  2643.                 inc de
  2644.                 ld a,(hl)
  2645.                 or 0xff
  2646.                 ld (de),a
  2647.                 inc de
  2648.                 inc hl
  2649.                 djnz 1b
  2650.                 ret
  2651.  
  2652. _pal_tsf_1:
  2653.                 ld b,16
  2654. 1               ld a,(hl)
  2655.                 or 0x1f     ;b00011111
  2656.                 ld (de),a
  2657.                 inc hl
  2658.                 inc de
  2659.                 ld a,(hl)
  2660.                 or 0xff
  2661.                 ld (de),a
  2662.                 inc de
  2663.                 inc hl
  2664.                 djnz 1b
  2665.                 ret        
  2666. _pal_tsf_0:
  2667.                 ld b,32
  2668.                 ld a,0xff
  2669. 1               ld (de),a
  2670.                 inc de
  2671.                 djnz 1b
  2672.                 ret
  2673.  
  2674. _pal_tsf_4:
  2675.                 ld b,16
  2676. 1               ld a,(hl)
  2677.                 and 0x1f ;b00011111
  2678.                 ld (de),a
  2679.                 inc hl
  2680.                 inc de
  2681.                 ld a,(hl)
  2682.                 ld (de),a
  2683.                 inc de
  2684.                 inc hl
  2685.                 djnz 1b
  2686.                 ret
  2687.  
  2688. _pal_tsf_5:
  2689.                 ld b,16
  2690. 1               ld a,(hl)
  2691.                 and 0x0c ;b00001100
  2692.                 ld (de),a
  2693.                 inc hl
  2694.                 inc de
  2695.                 ld a,(hl)
  2696.                 ld (de),a
  2697.                 inc de
  2698.                 inc hl
  2699.                 djnz 1b
  2700.                 ret        
  2701. _pal_tsf_6:
  2702.                 ld b,16
  2703. 1               ld a,(hl)
  2704.                 and 0x0c ;b00001100
  2705.                 ld (de),a
  2706.                 inc hl
  2707.                 inc de
  2708.                 ld a,(hl)
  2709.                 and 0x1f   ;b00011111
  2710.                 ld (de),a
  2711.                 inc de
  2712.                 inc hl
  2713.                 djnz 1b
  2714.                 ret        
  2715. _pal_tsf_7:
  2716.                 ld b,32
  2717.                 ld a,0x0c ;00001100
  2718. 1               ld (de),a
  2719.                 inc de
  2720.                 djnz 1b
  2721.                 ret
  2722. ;===================
  2723. fade_toblack:
  2724.         ld hl,pal
  2725.         ld de,temppal
  2726.         ld bc,32
  2727.         ldir        ;;
  2728.  
  2729.  
  2730.  
  2731.         ld a,3 ;2
  2732. .fade0;
  2733.         halt
  2734.         halt
  2735.         halt
  2736.         halt
  2737.         halt
  2738. ;       halt
  2739.        
  2740.  
  2741.         push af
  2742.  
  2743.         add a,a ;x2
  2744.         add a,a ;x4
  2745.         add a,a ;x8
  2746.         add a,a ;x16
  2747.         add a,a ;x32
  2748.         ld l,a
  2749.         ld h,high _pal_bright   ;adr palette
  2750.         ld de,pal
  2751.         ld bc,32
  2752.         ldir
  2753.  
  2754.         ld a,1
  2755.         ld (setpalflag),a
  2756.  
  2757.        ;call waitkey
  2758.  
  2759.         pop af
  2760.         dec a
  2761.         cp 255
  2762.         jr nz,.fade0
  2763.  
  2764.  
  2765.         halt
  2766.         halt
  2767.         halt
  2768.         halt
  2769.         halt
  2770.  
  2771.        ret
  2772.  
  2773. fade_towhite:
  2774.         ld hl,pal
  2775.         ld de,temppal
  2776.         ld bc,32
  2777.         ldir        ;;
  2778.  
  2779.  
  2780.  
  2781.         ld a,4 ;2
  2782. .fade_w0;
  2783.         halt
  2784.         halt
  2785.         halt
  2786.         halt
  2787.         halt
  2788. ;       halt
  2789.        
  2790.  
  2791.         push af
  2792.  
  2793.         add a,a ;x2
  2794.         add a,a ;x4
  2795.         add a,a ;x8
  2796.         add a,a ;x16
  2797.         add a,a ;x32
  2798.         ld l,a
  2799.         ld h,high _pal_bright   ;adr palette
  2800.         ld de,pal
  2801.         ld bc,32
  2802.         ldir
  2803.  
  2804.         ld a,1
  2805.         ld (setpalflag),a
  2806.  
  2807.        ;call waitkey
  2808.  
  2809.         pop af
  2810.         inc a
  2811.         cp 8
  2812.         jr nz,.fade_w0
  2813.  
  2814.  
  2815.         halt
  2816.         halt
  2817.         halt
  2818.         halt
  2819.         halt
  2820.  
  2821.        ret
  2822.  
  2823. fade_fromwhite:
  2824.         ld hl,pal
  2825.         ld de,temppal
  2826.         ld bc,32
  2827.         ldir        ;;
  2828.  
  2829.  
  2830.  
  2831.         ld a,6 ;2
  2832. .fade_w1;
  2833.         halt
  2834.         halt
  2835.         halt
  2836.         halt
  2837.         halt
  2838. ;       halt
  2839.        
  2840.  
  2841.         push af
  2842.  
  2843.         add a,a ;x2
  2844.         add a,a ;x4
  2845.         add a,a ;x8
  2846.         add a,a ;x16
  2847.         add a,a ;x32
  2848.         ld l,a
  2849.         ld h,high _pal_bright   ;adr palette
  2850.         ld de,pal
  2851.         ld bc,32
  2852.         ldir
  2853.  
  2854.         ld a,1
  2855.         ld (setpalflag),a
  2856.  
  2857.        ;call waitkey
  2858.  
  2859.         pop af
  2860.         dec a
  2861.         cp 3
  2862.         jr nz,.fade_w1
  2863.  
  2864.  
  2865.  
  2866.         halt
  2867.         halt
  2868.         halt
  2869.         halt
  2870.         halt
  2871.  
  2872.         ld hl,temppal
  2873.         ld bc,32
  2874.         ld de,pal
  2875.         ldir
  2876.         ld a,1
  2877.         ld (setpalflag),a
  2878.         halt
  2879.  
  2880.         ret
  2881. ;------------------------------------
  2882. fade_fromblack:
  2883.         ld hl,pal
  2884.         ld de,temppal
  2885.         ld bc,32
  2886.         ldir        ;;
  2887.  
  2888.         ld a,0 ;2
  2889. .fade_b1;
  2890.         halt
  2891.         halt
  2892.         halt
  2893.         halt
  2894.         halt
  2895. ;       halt
  2896.        
  2897.  
  2898.         push af
  2899.  
  2900.         add a,a ;x2
  2901.         add a,a ;x4
  2902.         add a,a ;x8
  2903.         add a,a ;x16
  2904.         add a,a ;x32
  2905.         ld l,a
  2906.         ld h,high _pal_bright   ;adr palette
  2907.         ld de,pal
  2908.         ld bc,32
  2909.         ldir
  2910.  
  2911.         ld a,1
  2912.         ld (setpalflag),a
  2913.  
  2914.        ;call waitkey
  2915.  
  2916.         pop af
  2917.         inc a
  2918.         cp 4
  2919.         jr nz,.fade_b1
  2920.  
  2921.         halt
  2922.         halt
  2923.         halt
  2924.         halt
  2925.         halt
  2926.  
  2927.         ld hl,temppal
  2928.         ld bc,32
  2929.         ld de,pal
  2930.         ldir
  2931.         ld a,1
  2932.         ld (setpalflag),a
  2933.         halt
  2934.  
  2935.         ret