?login_element?

Subversion Repositories NedoOS

Rev

Rev 1510 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.         DEVICE ZXSPECTRUM128
  2.         include "../../_sdk/sys_h.asm"
  3.  
  4. INTSTACK=0x3f00
  5. STACK=0x4000
  6. scrbase=0x8000
  7.  
  8. music=0x4000
  9.  
  10.  
  11.         org PROGSTART
  12. begin
  13.         ld sp,STACK
  14.  
  15.         ld e,0
  16.         OS_SETGFX ;e=0:EGA, e=2:MC, e=3:6912, e=6:text ;+SET FOCUS ;e=-1: disable gfx (out: e=old gfxmode)
  17.         ld e,0 ;color byte
  18.         OS_CLS
  19.         ld e,1
  20.         OS_SETSCREEN
  21.         ld e,0 ;color byte
  22.         OS_CLS
  23.  
  24.         OS_GETMAINPAGES
  25. ;dehl=номера страниц в 0000,4000,8000,c000
  26.         ld a,h
  27.         ld (pg16c0),a
  28.         ld a,l
  29.         ld (pg16c1),a
  30.         ld a,e
  31.         LD (pgmusic),A
  32.  
  33.         ;OS_GETSCREENPAGES
  34. ;de=страницы 0-го экрана (d=старшая), hl=страницы 1-го экрана (h=старшая)
  35.         ;ld a,e
  36.         ;ld (setpgs_scr0_low),a
  37.         ;ld a,d
  38.         ;ld (setpgs_scr0_high),a
  39.         ;ld a,l
  40.         ;ld (setpgs_scr1_low),a
  41.         ;ld a,h
  42.         ;ld (setpgs_scr1_high),a
  43.  
  44.         ld a,(pg16c0)
  45.         SETPG4000        
  46.         ld de,bmpfilename
  47.         OS_OPENHANDLE
  48.         push bc
  49.         ld de,0x4000
  50.         ld hl,0x4000
  51.         OS_READHANDLE
  52.         ld a,(pg16c1)
  53.         SETPG4000        
  54.         pop bc
  55.         push bc
  56.         ld de,0x4000
  57.         ld hl,0x4000
  58.         OS_READHANDLE
  59.         pop bc
  60.         push bc
  61.         ld hl,32
  62.         ld de,palbufATM3
  63.         OS_READHANDLE
  64.        
  65.         ld hl,palbufATM3
  66.         ld de,palbufATM3RGB
  67.         ld b,16
  68. mkpalATM3RGB
  69.         push bc
  70.         ld a,(hl)
  71.         inc hl
  72.         push hl
  73.         ld h,(hl)
  74.         ld l,a
  75.         push de
  76.        
  77.         call calchexcolor ;hl=color (DDp palette) ;out: ;b=B, d=R, e=G
  78.  
  79.         ld a,e ;G
  80.         add a,a
  81.         add a,a
  82.         add a,a
  83.         add a,a
  84.         or d ;R
  85.         pop de
  86.         ld c,a ;GR
  87.         ld a,b
  88.         add a,a
  89.         add a,a
  90.         add a,a
  91.         add a,a
  92.         ld (de),a ;B0
  93.         inc de
  94.         ld a,c
  95.         ld (de),a ;GR
  96.         inc de
  97.         pop hl
  98.         inc hl
  99.         pop bc
  100.         djnz mkpalATM3RGB
  101.  
  102.         ld hl,palbufATM3RGB
  103.         ld de,palbufATM3
  104.         ld lx,8 ;lx=brightness
  105.         CALL recolour
  106.        
  107.         pop bc
  108.         OS_CLOSEHANDLE
  109.         ld de,texfilename
  110.         OS_OPENHANDLE
  111.  
  112.         ld hl,ttexpgs
  113.         ld c,32
  114. getttexpgs0
  115.         push bc
  116.         push hl
  117.  
  118.         push bc
  119.         OS_NEWPAGE
  120.         ld a,e
  121.         SETPG4000
  122.         pop bc        
  123.         push de
  124.         ld de,0x4000 ;addr
  125.         ld hl,0x4000 ;size
  126.         OS_READHANDLE        
  127.         pop de
  128.        
  129.         pop hl
  130.         ld (hl),e
  131.         inc hl
  132.         pop bc
  133.         dec c
  134.         jr nz,getttexpgs0
  135.  
  136.         OS_CLOSEHANDLE
  137.  
  138.         ld hl,0x4000+0x1f40
  139.         ld de,palbufATM2
  140.         ld b,16
  141. copypal0
  142.         ld a,(hl)
  143.         inc hl
  144.         ld (de),a
  145.         inc de
  146.         ld (de),a
  147.         inc de
  148.         djnz copypal0
  149.  
  150.         call setpgmusic
  151.         ld hl,wasmusic
  152.         ld de,music
  153.         ld bc,sz_music
  154.         ldir
  155.  
  156.         ld hl,MDLADDR
  157.         call INIT
  158.  
  159.         ld a,(pgmusic)
  160.         ld hl,PLAY
  161.         OS_SETMUSIC
  162.  
  163.         call swapimer
  164. MUSICPATTERNSIZE=256;192
  165.         OS_GETTIMER ;dehl
  166.         ld (oldtimer),hl;de
  167.  
  168. showpic_mainloop
  169.  
  170. showpic0
  171.         call setpgs_scr0      
  172.         call showpic
  173.         ld de,palbufATM2
  174.         OS_SETPAL
  175.         call halt_testquit
  176.         ld e,0
  177.         OS_SETSCREEN
  178.  
  179.         call setpgs_scr1
  180.         call showpic
  181.         call halt_testquit
  182.         ld e,1
  183.         OS_SETSCREEN
  184.        
  185.         call gettimer        
  186.         ld bc,MUSICPATTERNSIZE
  187.         or a
  188.         sbc hl,bc
  189.         jr c,showpic0
  190.         call settimer
  191.  
  192.         ld de,blackpal
  193.         OS_SETPAL
  194.  
  195.         call setpgs_scr0      
  196.         call showpic16c
  197.         ;ld de,palbufATM3
  198.         ;OS_SETPAL
  199.         call halt_testquit
  200.         ld e,0
  201.         OS_SETSCREEN
  202.  
  203.         call setpgs_scr1
  204.         call showpic16c
  205.         call halt_testquit
  206.         ld e,1
  207.         OS_SETSCREEN
  208.  
  209.         ld lx,0
  210. showpic1_show
  211.         inc lx
  212.         ld hl,palbufATM3RGB
  213.         ld de,palbufATM3
  214.         call recolour
  215.         push ix
  216.         ld de,palbufATM3
  217.         OS_SETPAL
  218.         halt
  219.         halt
  220.         halt
  221.         halt
  222.         halt
  223.         halt
  224.         halt
  225.         halt
  226.         pop ix
  227.         ld a,lx
  228.         cp 8
  229.         jr nz,showpic1_show
  230.  
  231. showpic1
  232.         call gettimer        
  233.         ld bc,MUSICPATTERNSIZE;-(8*8)
  234.         or a
  235.         sbc hl,bc
  236.         jr c,showpic1
  237.  
  238.         ld lx,8
  239. showpic1_hide
  240.         ld hl,palbufATM3RGB
  241.         ld de,palbufATM3
  242.         call recolour
  243.         push ix
  244.         ld de,palbufATM3
  245.         OS_SETPAL
  246.         halt
  247.         halt
  248.         halt
  249.         halt
  250.         halt
  251.         halt
  252.         halt
  253.         halt
  254.         pop ix
  255.         inc lx
  256.         ld a,lx
  257.         cp 16
  258.         jr nz,showpic1_hide
  259.  
  260.         ld hl,0
  261.         call settimer
  262.        
  263.         jp showpic_mainloop
  264. quit
  265.         call swapimer
  266.  
  267.           ld a,(pgmusic)
  268.           ld hl,MUTE
  269.           OS_SETMUSIC
  270.           halt
  271.         ;call setpgmusic
  272.         ;call MUTE
  273.         QUIT
  274.  
  275. halt_testquit
  276.         YIELDGETKEY ;out: nz=nokey, a=keylang, c=keynolang
  277.         cp key_esc
  278.         jr z,quit
  279.         ret
  280.  
  281. gettimer
  282.         ;ld hl,(timer)
  283.         OS_GETTIMER ;dehl
  284.         ;ex de,hl
  285. oldtimer=$+1
  286.         ld de,0
  287.         ld (oldtimer),hl
  288.         or a
  289.         sbc hl,de ;hl=time delta
  290. mytimer=$+1
  291.         ld de,0
  292.         add hl,de
  293. settimer
  294.         ;ld (timer),hl
  295.         ld (mytimer),hl
  296.         ret
  297.  
  298. pg16c0
  299.         db 0
  300. pg16c1
  301.         db 0
  302.  
  303. showpic
  304. showpiccurpgpoi=$+1
  305.         ld hl,ttexpgs
  306.         ld de,0x8000
  307.         call ldirpg
  308.         call ldirpg      
  309.         res 5,l
  310.         ld (showpiccurpgpoi),hl
  311.         ret
  312.  
  313. showpic16c
  314.         ld de,0x8000
  315.         ld a,(pg16c0)
  316.         call ldirpg_a
  317.         ld a,(pg16c1)
  318.         call ldirpg_a
  319.         ret
  320.  
  321. setpgmusic
  322. pgmusic=$+1
  323.         ld a,0
  324.         SETPG4000
  325.         ret
  326.  
  327. swapimer
  328.         di
  329.         ld de,0x0038
  330.         ld hl,oldimer
  331.         ld bc,3
  332. swapimer0
  333.         ld a,(de)
  334.         ldi ;[oldimer] -> [0x0038]
  335.         dec hl
  336.         ld (hl),a ;[0x0038] -> [oldimer]
  337.         inc hl
  338.         jp pe,swapimer0
  339.         ei
  340.         ret
  341. oldimer
  342.         jp on_int ;заменится на код из 0x0038
  343.         jp 0x0038+3
  344.  
  345. on_int
  346. ;restore stack with de
  347.         ld (on_int_hl),hl
  348.         ld (on_int_sp),sp
  349.         pop hl
  350.         ld (on_int_sp2),sp
  351.         ld (on_int_jp),hl
  352.         ld sp,INTSTACK
  353.         push af
  354.         push bc
  355.         push de
  356.  
  357. ;imer_curscreen_value=$+1
  358.          ;ld a,0
  359.          ;ld bc,0x7ffd
  360.          ;out (c),a
  361.  
  362.         ex de,hl;ld hl,0
  363. on_int_sp=$+1
  364.         ld (0),hl ;восстановили запоротый стек
  365.        
  366.         push ix
  367.         push iy
  368.         ex af,af' ;'
  369.         exx
  370.         push af
  371.         push bc
  372.         push de
  373.         push hl
  374.         ;ld a,(curscreen)
  375.         ;ld e,a
  376.         ;OS_SETSCREEN ;вызываем здесь, а не в рандомном месте, иначе даже с одной задачей можем получить непредсказуемую задержку, которую не фиксирует наш таймер? с несколькими задачами надо учитывать и системный - TODO
  377. ;curpalette=$+1
  378.         ;ld de,wolfpal
  379.         ;OS_SETPAL
  380. ;        GET_KEY
  381. ;        ld (curkey),a
  382.        
  383.         call oldimer ;ei
  384.        
  385.         pop hl
  386.         pop de
  387.         pop bc
  388.         pop af
  389.         exx
  390.         ex af,af' ;'
  391.         pop iy
  392.         pop ix
  393.        
  394.         ;ld hl,(timer)
  395.         ;inc hl
  396.         ;ld (timer),hl
  397.  
  398.         pop de
  399.         pop bc
  400.         pop af
  401. on_int_hl=$+1
  402.         ld hl,0
  403. on_int_sp2=$+1
  404.         ld sp,0
  405.         ;ei
  406. on_int_jp=$+1
  407.         jp 0
  408.  
  409. setpgs_scr0
  410.         ld a,(user_scr0_low) ;ok
  411.         SETPG32KLOW
  412.         ld a,(user_scr0_high) ;ok
  413.         SETPG32KHIGH
  414.         ret
  415.  
  416. setpgs_scr1
  417.         ld a,(user_scr1_low) ;ok
  418.         SETPG32KLOW
  419.         ld a,(user_scr1_high) ;ok
  420.         SETPG32KHIGH
  421.         ret
  422.  
  423. ldirpg
  424.         ld a,(hl)
  425.         inc l
  426. ldirpg_a
  427.         SETPG4000
  428.         push hl
  429.         ld hl,0x4000
  430.         ld bc,0x4000
  431.         ldir
  432.         pop hl
  433.         ret
  434.  
  435. recolour
  436. ;hl=palfrom (RGB)
  437. ;de=palto (DDp)
  438. ;lx=brightness=0..15
  439.         di
  440.         ld (recoloursp),sp
  441.         ld sp,hl
  442.        ld h,tbright/256 ;once
  443.         ld hx,16
  444. bripalATM3
  445.          ;ld a,(hl) ;B0
  446.          ;inc hl
  447.          ;push hl
  448.          ;ld b,(hl) ;GR
  449.        pop bc
  450.        ld a,c
  451.          ;ld h,tbright/256
  452. ;de=palto
  453. ;h=tbright/256
  454. ;lx=brightness
  455. ;a,b = B0,GR
  456.          add a,lx
  457.         ld l,a
  458.         ld c,(hl) ;B colour component with brightness
  459.         ld a,b
  460.         and 0xf0
  461.          add a,lx
  462.         ld l,a
  463.         ld a,b
  464.         ld b,(hl) ;G colour component with brightness
  465.         add a,a
  466.         add a,a
  467.         add a,a
  468.         add a,a
  469.          add a,lx
  470.         ld l,a
  471.         ld l,(hl) ;R colour component with brightness
  472.  
  473.        ld a,b ;G
  474.        rlca ;g??G???? ;G10
  475.        xor l ;R
  476.        and 0b10010000;0b01000010 ;R10
  477.        xor l;gr?G??R?
  478.        rlca ;r?G??R?g
  479.        xor c ;B
  480.        and 0b10100101;0b01000010 ;B10
  481.        xor c;rbG??RBg
  482.        rrca ;grbG??RB
  483.         or 0b00001100 ;unused bits
  484.         ld (de),a ;low %grbG11RB
  485.         inc de ;TODO ld (),a
  486.  
  487.        ld a,b ;G
  488.        rlca ;?g??G??? ;G32
  489.        xor l ;R
  490.        and 0b01001000;0b00100001 ;R32
  491.        xor l;?gr?G??R
  492.        rlca ;gr?G??R?
  493.        xor c ;B
  494.        and 0b11010010;0b00100001 ;B32
  495.        xor c;grbG??RB
  496.         or 0b00001100 ;unused bits
  497.         ld (de),a ;high %grbG11RB
  498.         inc de ;TODO ld (),a
  499.  
  500.          ;pop hl
  501.          ;inc hl
  502.          dec hx
  503.          jp nz,bripalATM3 ;TODO dup..edup
  504. recoloursp=$+1
  505.         ld sp,0
  506.         ei
  507.         ret
  508.  
  509. calchexcolor ;hl=color (DDp palette) ;out: ;b=B, d=R, e=G
  510. ;keep c!!!
  511. ;DDp palette: %grbG11RB(low),%grbG11RB(high), инверсные
  512. ;high B, high b, low B, low b
  513.         ld b,0;0xff
  514.         ld de,0;0xffff
  515.         ld a,h
  516.        cpl
  517.         rra
  518.         rl b ;B high
  519.         rra
  520.         rl d ;R high
  521.         rra
  522.         rra
  523.         rra
  524.         rl e ;G high
  525.         rra
  526.         rl b ;b high
  527.         rra
  528.         rl d ;r high
  529.         rra
  530.         rl e ;g high
  531.         ld a,l
  532.        cpl
  533.         rra
  534.         rl b ;B low
  535.         rra
  536.         rl d ;R low
  537.         rra
  538.         rra
  539.         rra
  540.         rl e ;G low
  541.         rra
  542.         rl b ;b low
  543.         rra
  544.         rl d ;r low
  545.         rra
  546.         rl e ;g low
  547. ;b=B
  548. ;d=R
  549. ;e=G
  550.         ret
  551.  
  552. calcRGBtopal ;e=B, d=G, l=R ;out: b(high),c=%grbG11RB
  553.         call calcRGBtopal_pp
  554.         ld b,a
  555.         call calcRGBtopal_pp
  556.         ld c,a
  557.         ret
  558.  
  559. calcRGBtopal_pp
  560. ;e=B, d=G, l=R
  561. ;DDp palette: %grbG11RB(low),%grbG11RB(high), инверсные
  562.         xor a
  563.         rl e  ;B
  564.         rra
  565.         rl l  ;R
  566.         rra
  567.         rrca
  568.         rrca
  569.         rl d  ;G
  570.         rra
  571.         rl e  ;b
  572.         rra
  573.         rl l  ;r
  574.         rra
  575.         rl d  ;g
  576.         rra
  577.         cpl
  578.         ret
  579.  
  580. texfilename
  581.         db "noise/forest.dat",0
  582. bmpfilename
  583.         db "noise/forest.16c",0
  584.  
  585. blackpal
  586.         ds 32,0xff
  587.  
  588. palbufATM2
  589.         ds 32
  590.  
  591. palbufATM3RGB
  592.         ds 32
  593.  
  594. palbufATM3
  595.         ds 32
  596.  
  597. ;timer
  598. ;        dw 0
  599.        
  600.         align 256
  601. ttexpgs
  602.         ds 32
  603.  
  604.  
  605.         macro BRIGHTBYTE x
  606. _=x
  607.         if _>15
  608. _=15
  609.         endif
  610. _g0=~_&1
  611. _g1=(~_>>1)&1
  612. _g2=(~_>>2)&1
  613. _g3=(~_>>3)&1
  614. ;0g20G3G3
  615.         ;db _
  616.         db (_g0<<6)+(_g2<<5)+(_g1<<3)+(_g3<<2)+(_g1<<1)+(_g3<<0)
  617.         endm
  618.  
  619.         align 256
  620. tbright
  621. ;brightness levels (black 0..7 less than original, 8 equal, 9..15 to white)
  622. ;0, 1/12, 1/8, 3/16, 2/8, 3/8, 4/8, 6/8, 1
  623. _lev=0
  624.         dup 16 ;colour component level
  625. _antilev=15-_lev
  626.         BRIGHTBYTE _lev*0
  627.         BRIGHTBYTE _lev/12
  628.         BRIGHTBYTE _lev*1/8
  629.         BRIGHTBYTE _lev*3/16
  630.         BRIGHTBYTE _lev*2/8
  631.         BRIGHTBYTE _lev*3/8
  632.         BRIGHTBYTE _lev*4/8
  633.         BRIGHTBYTE _lev*6/8
  634.  
  635.         BRIGHTBYTE _lev
  636.  
  637.         BRIGHTBYTE 15-(_antilev*6/8)
  638.         BRIGHTBYTE 15-(_antilev*4/8)
  639.         BRIGHTBYTE 15-(_antilev*3/8)
  640.         BRIGHTBYTE 15-(_antilev*2/8)
  641.         BRIGHTBYTE 15-(_antilev*3/16)
  642.         BRIGHTBYTE 15-(_antilev*1/8)
  643.         BRIGHTBYTE 15
  644.  
  645. _lev=_lev+1
  646.         edup
  647.  
  648. wasmusic
  649.         disp music
  650.         include "../../_sdk/ptsplay.asm"
  651. MDLADDR
  652.         incbin "NOISE20.pt3"
  653.         ent
  654. sz_music=$-wasmusic
  655.  
  656. end
  657.  
  658.         display "End=",end
  659.         ;display "Free after end=",/d,#c000-end
  660.         display "Size ",/d,end-begin," bytes"
  661.        
  662.         savebin "noise.com",begin,end-begin
  663.  
  664.         LABELSLIST "../../../us/user.l"
  665.