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