Subversion Repositories NedoOS

Rev

Rev 801 | Rev 840 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download

  1.         DEVICE ZXSPECTRUM128
  2.         include "../../_sdk/sys_h.asm"  
  3.  
  4. STACK=0x4000;0x61a8
  5. GAMESTACK=0x4000;0xFFFF
  6. L_FDFD=0xfdfd
  7. L_FE00=0xfe00
  8.  
  9. scrbase=0x4000+4
  10. sprmaxwid=32
  11. sprmaxhgt=32
  12. scrwid=160 ;double pixels
  13. scrhgt=192;200
  14. INTSTACK=0x3f00
  15. tempsp=0x3f06 ;6 bytes for prspr
  16. ;UVSCROLL_SCRWID=320 ;8*(TILEMAPWID-2)
  17. ;UVSCROLL_SCRHGT=192 ;(фхышЄё  эр 16!!!) ;8*(TILEMAPHGT-2) ;ўЄюс√ т√тюфшЄ№ тёхуфр 12 ьхЄрЄрщыют (3 сыюър яю 8) яю т√ёюЄх
  18.  
  19. screenYtable=0x8b00
  20.  
  21. EGA=1
  22.  
  23.         org PROGSTART
  24. begin
  25.         jp begin2 ;/prsprqwid (sprites in file are made so that they return here)
  26. begin2
  27.         ld sp,STACK
  28.         OS_HIDEFROMPARENT
  29.  
  30.         ld e,3+8+0x80 ;6912+noturbo+keep
  31.         OS_SETGFX ;e=0:EGA, e=2:MC, e=3:6912, e=6:text ;+SET FOCUS ;e=-1: disable gfx (out: e=old gfxmode)
  32.  
  33.         ;ld e,1
  34.         ;OS_SETSCREEN
  35.         ld e,0 ;color byte
  36.         OS_CLS
  37.         ;ld e,0
  38.         ;OS_SETSCREEN
  39.         ;ld e,0 ;color byte
  40.         ;OS_CLS
  41.  
  42.         OS_GETMAINPAGES
  43. ;dehl=pages in 0000,4000,8000,c000
  44.         ld a,e
  45.         ld (pggfx),a
  46.         ld a,h
  47.         ld (pgcode8000),a
  48.         ld a,l
  49.         ld (pgcodec000),a
  50.         ;jr $
  51.  
  52.         OS_NEWPAGE
  53.         ld a,e
  54.         ld (pgmain4000),a
  55.  
  56.         if 1==0
  57.         ld de,res_path
  58.         OS_CHDIR
  59.  
  60.         call setpgsscr40008000
  61.  
  62.         ld de,emptypal
  63.         OS_SETPAL
  64.         ld de,bmpfilename
  65.         call openstream_file
  66.         call readbmphead_pal
  67.         call readbmpscr
  68.         call closestream_file
  69.         ld de,pal
  70.         OS_SETPAL
  71.        
  72.         call setpgsmain40008000
  73.  
  74.         ;ld b,50
  75.         ;halt
  76.         ;djnz $-1
  77.         YIELDGETKEYLOOP
  78.  
  79.         ld e,3+8+0x80 ;6912+noturbo+keep
  80.         OS_SETGFX ;e=0:EGA, e=2:MC, e=3:6912, e=6:text ;+SET FOCUS ;e=-1: disable gfx (out: e=old gfxmode)
  81.         ld e,0 ;color byte
  82.         OS_CLS
  83.         ld de,standardpal
  84.         OS_SETPAL
  85.         YIELD
  86.         endif
  87.  
  88.         if 1==1
  89.         ld a,(user_scr0_high) ;ok
  90.         SETPG32KLOW
  91.         ld hl,0x4000
  92.         ld de,0x4000+0x4000
  93.         ld bc,0x4000
  94.         ldir
  95.         ;ld a,(user_scr0_high)
  96.         SETPG16K
  97.         ld a,(pgcode8000)
  98.         SETPG32KLOW
  99.         endif
  100.         ld a,(user_scr0_high) ;ok
  101.         SETPG16K
  102.        
  103.         call swapimer
  104.  
  105.         if EGA
  106.         ld hl,prsprqwid
  107.         ld (0x0101),hl ;sprites in file are made so that they return in 0x0100
  108.         endif
  109.  
  110.         YIELDGETKEYLOOP
  111.        
  112.         ;jr $
  113.         jp GO
  114.  
  115.         ;include "pal.ast" ;slabpal
  116. standardpal
  117.         STANDARDPAL
  118. pal
  119.         ds 32,0xff
  120. emptypal
  121.         ds 32,0xff
  122.  
  123. jphl
  124.         jp (hl)
  125.  
  126. CheckBreak
  127.         ld a,0xfe
  128.         in a,(0xfe)
  129.         rra
  130.         ret c
  131.         ld a,0x7f
  132.         in a,(0xfe)
  133.         rra
  134.         ret
  135. PlayMusic_CheckQuit
  136.         call PlayMusic
  137.         call CheckBreak
  138.         ret c
  139. quiter
  140.         if 1==0
  141.         halt
  142. pgmuznum=$+1
  143.         ld a,0
  144.         SETPG32KHIGH
  145.           ld hl,muz
  146.           OS_SETMUSIC
  147.         halt
  148.         endif
  149.         call swapimer
  150.         im 1
  151.         QUIT
  152.  
  153. redattr_killable2b
  154.         dw 0
  155.  
  156. ;L_5B00 ;= #5b00
  157. ;        db 0
  158.  
  159. setpggfxc000
  160. pggfx=$+1
  161.         ld a,0
  162.         SETPG32KHIGH
  163.         ret
  164. setpgcodec000
  165. pgcodec000=$+1
  166.         ld a,0
  167.         SETPG32KHIGH
  168.         ret
  169.  
  170. swapimer
  171.         di
  172.         ld de,0x0038
  173.         ld hl,oldimer
  174.         ld bc,3
  175. swapimer0
  176.         ld a,(de)
  177.         ldi ;[oldimer] -> [0x0038]
  178.         dec hl
  179.         ld (hl),a ;[0x0038] -> [oldimer]
  180.         inc hl
  181.         jp pe,swapimer0
  182.         ei
  183.         ret
  184. oldimer
  185.         jp on_int ;чрьхэшЄё  эр ъюф шч 0x0038
  186.         jp 0x0038+3    
  187.  
  188. reter
  189.         ret
  190.  
  191. tstarttime       DB       #00,#00,#00
  192. curgametimer       DB       #00,#00,#00
  193. stoptimer       DB       #00
  194. curtimerlow       DB       #00
  195. ;
  196. on_int
  197. ;restore stack with de
  198.         EX DE,HL
  199.         EX (SP),HL ;de="hl", stack contains "de"
  200.         LD (on_int_jp),HL
  201.         LD (on_int_sp),SP
  202.         LD SP,INTSTACK
  203.         push af
  204.         push bc
  205.         push de ;"hl"
  206.         exx
  207.         ex af,af' ;'
  208.         push af
  209.         push bc
  210.         push de
  211.         push hl
  212.         push ix
  213.         push iy
  214.         ;DI
  215. ;curscrnum_int=$+1
  216. ;        ld e,0
  217. ;        OS_SETSCREEN
  218.         call oldimer ;ei
  219.          GET_KEY
  220.          jr nz,Imer_nofocus
  221.          ;ld a,(user_scr0_high) ;ok
  222.          ;SETPG16K ;TODO redraw screen when retake focus???
  223. Imer_nofocus
  224.         ;LD     A,(stoptimer)
  225.         ;OR     A
  226.         ;CALL   Z,DecTimer
  227.         pop iy
  228.         pop ix
  229.         pop hl
  230.         pop de
  231.         pop bc
  232.         pop af
  233.         ex af,af' ;'
  234.         exx
  235.         pop hl
  236.         pop bc
  237.         pop af        
  238. on_int_sp=$+1
  239.         ld sp,0
  240.         pop de
  241.         ei
  242. on_int_jp=$+1
  243.         jp 0
  244. ;
  245. ;
  246. RIGHTPIX=0x38;0xb8;%10111000
  247. LEFTPIX=0x07;0x47;%01000111
  248.         macro FONTBYTE
  249.         ld a,(de)
  250.         ld c,a
  251.         xor a
  252.         rl c
  253.         jr nc,$+4
  254.          or LEFTPIX
  255.         rl c
  256.         jr nc,$+4
  257.          or RIGHTPIX
  258.         ld (hl),a
  259.         ld a,h
  260.         add a,0x40
  261.         ld h,a
  262.         xor a
  263.         rl c
  264.         jr nc,$+4
  265.          or LEFTPIX
  266.         rl c
  267.         jr nc,$+4
  268.          or RIGHTPIX
  269.         ld (hl),a
  270.         ld a,h
  271.         add a,0x20-0x40
  272.         ld h,a
  273.         xor a
  274.         rl c
  275.         jr nc,$+4
  276.          or LEFTPIX
  277.         rl c
  278.         jr nc,$+4
  279.          or RIGHTPIX
  280.         ld (hl),a
  281.         ld a,h
  282.         add a,0x40
  283.         ld h,a
  284.         xor a
  285.         rl c
  286.         jr nc,$+4
  287.          or LEFTPIX
  288.         rl c
  289.         jr nc,$+4
  290.          or RIGHTPIX
  291.         ld (hl),a
  292.         endm
  293.  
  294. PrintCharA_EGA
  295.         push bc
  296.         push de
  297.         push hl
  298.        push af
  299.         call setpgsscr40008000
  300.         LD      DE,(curprintyx)
  301.         sla e
  302.         sla e
  303.         sla e
  304.         ld a,d ;x
  305.          add a,4
  306.         ld l,e ;y
  307.         ld h,0
  308.         ld d,h
  309.         ld e,l
  310.         add hl,hl
  311.         add hl,hl
  312.         add hl,de ;*5
  313.          add hl,hl
  314.          add hl,hl
  315.          add hl,hl ;*40
  316.         add a,l
  317.         ld l,a
  318.         ld a,h
  319.         adc a,0x40
  320.         ld h,a
  321.        pop af
  322.         PUSH    HL
  323.         LD      DE,font-256;L_BE02
  324.         LD      H,#00
  325.         LD      L,A
  326.         ADD     HL,HL
  327.         ADD     HL,HL
  328.         ADD     HL,HL
  329.         ADD     HL,DE
  330.         EX      DE,HL
  331.         POP     HL
  332.         LD      hx,#08
  333.  
  334. PrintCharA_EGA0
  335.         FONTBYTE
  336.         ld bc,40-0x6000
  337.         add hl,bc
  338.         INC     DE
  339.         dec hx
  340.         jr nz,PrintCharA_EGA0
  341.        
  342.         LD      DE,(curprintyx)
  343.         INC     D
  344.         LD      A,D
  345.         CP      #20
  346.         JR      NZ,PrintCharA_EGAq
  347.         INC     E
  348.         LD      D,#00
  349.         LD      A,E
  350.         CP      #18
  351.         JR      NZ,PrintCharA_EGAq
  352.         LD      E,#00
  353. PrintCharA_EGAq
  354.         LD      (curprintyx),DE
  355.         call setpgsmain40008000
  356.         pop hl
  357.         pop de
  358.         pop bc
  359.         ret
  360.        
  361. PrintCharA
  362.         PUSH    DE
  363.         PUSH    HL
  364.         PUSH    BC
  365.         PUSH    AF
  366.         LD      DE,(curprintyx)
  367.         LD      A,E
  368.         AND     #18
  369.         OR      #40
  370.         LD      H,A
  371.         LD      A,E
  372.         AND     #07
  373.         OR      A
  374.         RRA
  375.         RRA
  376.         RRA
  377.         RRA
  378.         ADD     A,D
  379.         LD      L,A
  380.         POP     AF
  381.         PUSH    HL
  382.         LD      DE,font-256;L_BE02
  383.         LD      H,#00
  384.         LD      L,A
  385.         ADD     HL,HL
  386.         ADD     HL,HL
  387.         ADD     HL,HL
  388.         ADD     HL,DE
  389.         EX      DE,HL
  390.         POP     HL
  391.         LD      B,#08
  392. L_C6EB  LD      A,(DE)
  393.         LD      (HL),A
  394.         INC     H
  395.         INC     DE
  396.         DJNZ    L_C6EB
  397.         LD      DE,(curprintyx)
  398.         INC     D
  399.         LD      A,D
  400.         CP      #20
  401.         JR      NZ,L_C705
  402.         INC     E
  403.         LD      D,#00
  404.         LD      A,E
  405.         CP      #18
  406.         JR      NZ,L_C705
  407.         LD      E,#00
  408. L_C705  LD      (curprintyx),DE
  409.         POP     BC
  410.         POP     HL
  411.         POP     DE
  412.         RET
  413. ;
  414. curprintyx       DW       #0000
  415. ;
  416. PrintStringHL
  417.         LD      A,(HL)
  418.         OR      A
  419.         RET     Z
  420.         CP      #16
  421.         JR      Z,L_C71C
  422.         CALL    PrintCharA
  423.         INC     HL
  424.         JR      PrintStringHL
  425. L_C71C  INC     HL
  426.         LD      E,(HL)
  427.         INC     HL
  428.         LD      D,(HL)
  429.         INC     HL
  430.         LD      (curprintyx),DE
  431.         JR      PrintStringHL
  432. ;
  433. PrintStringHL_EGA
  434.         LD      A,(HL)
  435.         OR      A
  436.         RET     Z
  437.         CP      #16
  438.         JR      Z,L_C71C_EGA
  439.         CALL    PrintCharA_EGA
  440.         INC     HL
  441.         JR      PrintStringHL_EGA
  442. L_C71C_EGA
  443.         INC     HL
  444.         LD      E,(HL)
  445.         INC     HL
  446.         LD      D,(HL)
  447.         INC     HL
  448.         LD      (curprintyx),DE
  449.         JR      PrintStringHL_EGA
  450.  
  451. font
  452.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  453.        DB       #00,#18,#3C,#18,#00,#18,#18,#00       ;..<.....
  454.        DB       #00,#36,#36,#6C,#00,#00,#00,#00       ;.66l....
  455.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  456.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  457.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  458.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  459.        DB       #00,#1C,#38,#00,#00,#00,#00,#00       ;..8.....
  460.        DB       #00,#0E,#1C,#1C,#1C,#1C,#0E,#00       ;........
  461.        DB       #00,#70,#38,#38,#38,#38,#70,#00       ;.p8888p.
  462.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  463.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  464.        DB       #00,#00,#00,#00,#00,#18,#18,#30       ;.......0
  465.        DB       #00,#00,#00,#3C,#3C,#00,#00,#00       ;...<<...
  466.        DB       #00,#00,#00,#00,#00,#18,#18,#00       ;........
  467.        DB       #00,#06,#0E,#1C,#38,#70,#60,#00       ;....8p`.
  468.        DB       #00,#3C,#72,#76,#7A,#72,#3C,#00       ;.<rvzr<.
  469.        DB       #00,#1C,#3C,#1C,#1C,#1C,#7E,#00       ;..<...~.
  470.        DB       #00,#7C,#0E,#0E,#3C,#70,#7E,#00       ;.|..<p~.
  471.        DB       #00,#7C,#0E,#3C,#0E,#0E,#7C,#00       ;.|.<..|.
  472.        DB       #00,#4E,#4E,#4E,#3E,#0E,#0E,#00       ;.NNN>...
  473.        DB       #00,#7C,#60,#7C,#0E,#0E,#7C,#00       ;.|`|..|.
  474.        DB       #00,#3C,#70,#7C,#72,#72,#3C,#00       ;.<p|rr<.
  475.        DB       #00,#7E,#06,#0E,#1C,#18,#18,#00       ;.~......
  476.        DB       #00,#3C,#72,#3C,#72,#72,#3C,#00       ;.<r<rr<.
  477.        DB       #00,#3C,#4E,#4E,#3E,#0E,#3C,#00       ;.<NN>.<.
  478.        DB       #00,#18,#18,#00,#00,#18,#18,#00       ;........
  479.        DB       #00,#18,#18,#00,#00,#18,#18,#30       ;.......0
  480.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  481.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  482.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  483.        DB       #7C,#0E,#0E,#0E,#1C,#00,#18,#00       ;|.......
  484.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  485.        DB       #00,#3C,#72,#72,#7E,#72,#72,#00       ;.<rr~rr.
  486.        DB       #00,#7C,#72,#7C,#72,#72,#7C,#00       ;.|r|rr|.
  487.        DB       #00,#3E,#70,#70,#70,#70,#3E,#00       ;.>pppp>.
  488.        DB       #00,#7C,#72,#72,#72,#72,#7C,#00       ;.|rrrr|.
  489.        DB       #00,#3E,#70,#7C,#70,#70,#3E,#00       ;.>p|pp>.
  490.        DB       #00,#3E,#70,#7C,#70,#70,#70,#00       ;.>p|ppp.
  491.        DB       #00,#3E,#70,#70,#76,#72,#3C,#00       ;.>ppvr<.
  492.        DB       #00,#72,#72,#7E,#72,#72,#72,#00       ;.rr~rrr.
  493.        DB       #00,#7F,#1C,#1C,#1C,#1C,#7F,#00       ;........
  494.        DB       #00,#0E,#0E,#0E,#4E,#4E,#3C,#00       ;....NN<.
  495.        DB       #00,#72,#72,#7C,#72,#72,#72,#00       ;.rr|rrr.
  496.        DB       #00,#70,#70,#70,#70,#70,#3E,#00       ;.ppppp>.
  497.        DB       #00,#3E,#75,#75,#75,#75,#75,#00       ;.>uuuuu.
  498.        DB       #00,#7C,#72,#72,#72,#72,#72,#00       ;.|rrrrr.
  499.        DB       #00,#3C,#72,#72,#72,#72,#3C,#00       ;.<rrrr<.
  500.        DB       #00,#7C,#72,#72,#7C,#70,#70,#00       ;.|rr|pp.
  501.        DB       #00,#3C,#72,#72,#72,#7A,#3C,#08       ;.<rrrz<.
  502.        DB       #00,#7C,#72,#72,#7C,#72,#72,#00       ;.|rr|rr.
  503.        DB       #00,#3C,#70,#3C,#0E,#0E,#7C,#00       ;.<p<..|.
  504.        DB       #00,#7F,#1C,#1C,#1C,#1C,#1C,#00       ;........
  505.        DB       #00,#72,#72,#72,#72,#72,#3C,#00       ;.rrrrr<.
  506.        DB       #00,#72,#72,#72,#72,#34,#18,#00       ;.rrrr4..
  507.        DB       #00,#71,#71,#75,#75,#75,#3E,#00       ;.qquuu>.
  508.        DB       #00,#72,#72,#3C,#72,#72,#72,#00       ;.rr<rrr.
  509.        DB       #00,#4E,#4E,#4E,#3E,#0E,#3C,#00       ;.NNN>.<.
  510.        DB       #00,#7E,#0E,#1C,#38,#70,#7E,#00       ;.~..8p~.
  511.        DB       #00,#1E,#1C,#1C,#1C,#1C,#1E,#00       ;........
  512.        DB       #00,#60,#70,#38,#1C,#0E,#06,#00       ;.`p8....
  513.        DB       #00,#78,#38,#38,#38,#38,#78,#00       ;.x8888x.
  514.        DB       #00,#08,#1C,#3E,#5D,#1C,#1C,#00       ;...>]...
  515.        DB       #00,#78,#38,#3C,#3A,#3A,#3C,#00       ;.x8<::<.
  516.        DB       #00,#76,#79,#79,#79,#79,#76,#00       ;.vyyyyv.
  517.        DB       #00,#3C,#72,#72,#7E,#72,#72,#00       ;.<rr~rr.
  518.        DB       #00,#7C,#70,#7C,#72,#72,#7C,#00       ;.|p|rr|.
  519.        DB       #00,#4E,#4E,#4E,#4E,#4E,#3E,#02       ;.NNNNN>.
  520.        DB       #00,#1E,#2E,#2E,#2E,#2E,#7E,#42       ;......~B
  521.        DB       #00,#3E,#70,#7C,#70,#70,#3E,#00       ;.>p|pp>.
  522.        DB       #00,#3E,#5D,#5D,#3E,#1C,#1C,#00       ;.>]]>...
  523.        DB       #00,#3E,#70,#70,#70,#70,#70,#00       ;.>ppppp.
  524.        DB       #00,#72,#72,#3C,#72,#72,#72,#00       ;.rr<rrr.
  525.        DB       #00,#72,#72,#76,#7A,#72,#72,#00       ;.rrvzrr.
  526.        DB       #08,#72,#72,#76,#7A,#72,#72,#00       ;.rrvzrr.
  527.        DB       #00,#72,#72,#7C,#72,#72,#72,#00       ;.rr|rrr.
  528.        DB       #00,#3E,#4E,#4E,#4E,#4E,#4E,#00       ;.>NNNNN.
  529.        DB       #00,#71,#7B,#75,#71,#71,#71,#00       ;.q{uqqq.
  530.        DB       #00,#72,#72,#7E,#72,#72,#72,#00       ;.rr~rrr.
  531.        DB       #00,#3C,#72,#72,#72,#72,#3C,#00       ;.<rrrr<.
  532.        DB       #00,#7E,#4E,#4E,#4E,#4E,#4E,#00       ;.~NNNNN.
  533.        DB       #00,#3E,#4E,#4E,#3E,#4E,#4E,#00       ;.>NN>NN.
  534.        DB       #00,#7C,#72,#72,#7C,#70,#70,#00       ;.|rr|pp.
  535.        DB       #00,#3E,#70,#70,#70,#70,#3E,#00       ;.>pppp>.
  536.        DB       #00,#7F,#1C,#1C,#1C,#1C,#1C,#00       ;........
  537.        DB       #00,#4E,#4E,#4E,#3E,#0E,#3C,#00       ;.NNN>.<.
  538.        DB       #00,#5D,#5D,#3E,#5D,#5D,#5D,#00       ;.]]>]]].
  539.        DB       #00,#7C,#72,#7C,#72,#72,#7C,#00       ;.|r|rr|.
  540.        DB       #00,#70,#70,#7C,#72,#72,#7C,#00       ;.pp|rr|.
  541.        DB       #00,#72,#72,#7C,#72,#72,#7C,#00       ;.rr|rr|.
  542.        DB       #00,#7C,#0E,#3C,#0E,#0E,#7C,#00       ;.|.<..|.
  543.        DB       #00,#75,#75,#75,#75,#75,#3E,#00       ;.uuuuu>.
  544.        DB       #00,#7C,#0E,#3E,#0E,#0E,#7C,#00       ;.|.>..|.
  545.        DB       #00,#75,#75,#75,#75,#75,#3F,#01       ;.uuuuu?.
  546.        DB       #00,#4E,#4E,#4E,#3E,#0E,#0E,#00       ;.NNN>...
  547.        DB       #00,#00,#3E,#70,#70,#3E,#00,#00       ;..>pp>..
  548.  
  549.  
  550. setpgsmain40008000
  551. pgmain4000=$+1
  552.         ld a,0
  553.         SETPG16K
  554. pgcode8000=$+1
  555.         ld a,0
  556.         SETPG32KLOW
  557.         ret
  558.  
  559. setpgsscr40008000;_current
  560.         call getuser_scr_low_cur
  561.         SETPG16K
  562.         call getuser_scr_high_cur
  563.         SETPG32KLOW
  564.         ret
  565.  
  566.         if 1==0
  567. setpgsscr40008000
  568.         call getuser_scr_low
  569.         SETPG16K
  570.         call getuser_scr_high
  571.         SETPG32KLOW
  572.         ret
  573.         endif
  574.  
  575. getuser_scr_low
  576. getuser_scr_low_patch=$+1
  577. getuser_scr_low_patchN=0xff&(user_scr0_low^user_scr1_low)
  578.         ld a,(user_scr1_low) ;ok
  579.         ret
  580.  
  581. getuser_scr_high
  582. getuser_scr_high_patch=$+1
  583. getuser_scr_high_patchN=0xff&(user_scr0_high^user_scr1_high)
  584.         ld a,(user_scr1_high) ;ok
  585.         ret
  586.  
  587. getuser_scr_low_cur
  588. getuser_scr_low_cur_patch=$+1
  589. getuser_scr_low_cur_patchN=0xff&(user_scr0_low^user_scr1_low)
  590.         ld a,(user_scr0_low) ;ok
  591.         ret
  592.  
  593. getuser_scr_high_cur
  594. getuser_scr_high_cur_patch=$+1
  595. getuser_scr_high_cur_patchN=0xff&(user_scr0_high^user_scr1_high)
  596.         ld a,(user_scr0_high) ;ok
  597.         ret
  598.  
  599. changescrpg_current
  600.         ld hl,getuser_scr_low_patch
  601.         ld a,(hl)
  602.         xor getuser_scr_low_patchN
  603.         ld (hl),a
  604.         ld hl,getuser_scr_high_patch
  605.         ld a,(hl)
  606.         xor getuser_scr_high_patchN
  607.         ld (hl),a
  608.         ld hl,getuser_scr_low_cur_patch
  609.         ld a,(hl)
  610.         xor getuser_scr_low_cur_patchN
  611.         ld (hl),a
  612.         ld hl,getuser_scr_high_cur_patch
  613.         ld a,(hl)
  614.         xor getuser_scr_high_cur_patchN
  615.         ld (hl),a
  616.  
  617.         ld a,1
  618. curscrnum=$+1
  619.         xor 0
  620.         ld ($-1),a
  621.         ret
  622.        
  623.         if 1==0
  624. changescrpg
  625.         call changescrpg_current
  626.         ld (curscrnum_int),a
  627.         ret
  628.         endif
  629.  
  630. primgega
  631. ;b=hgt,c=wid (/2)
  632. ;de=gfx
  633. ;hl=scr
  634.         push bc
  635.         call setpgsscr40008000
  636.         call setpggfxc000
  637.         pop bc
  638. primgega0
  639.         push bc
  640.         ld hx,b
  641.         push hl
  642.         ld bc,40
  643. primgegacolumn0
  644.         ld a,(de)
  645.         inc de
  646.         ld (hl),a
  647.         add hl,bc
  648.         dec hx
  649.         jr nz,primgegacolumn0
  650.         pop hl
  651.         ld a,0x9f;0xa0
  652.         cp h
  653.         ld bc,0x4000
  654.         adc hl,bc
  655.         jp pe,primgegacolumn0q ;т яюыютшэх ёыєўрхт
  656. ;8000->ё000 (эрфю 6000) шыш a000->e001 (эрфю 4001)
  657.          inc a
  658.         xor h
  659.         ld h,a
  660. primgegacolumn0q
  661.         pop bc
  662.         dec c
  663.         jr nz,primgega0
  664.         call setpgcodec000
  665.         jp setpgsmain40008000
  666.  
  667. clsega
  668.         call setpgsscr40008000
  669.         ld hl,0x4000
  670.         ld de,0x4001
  671.         ld bc,0x7fff
  672.         ld (hl),l;0
  673.         ldir
  674.         jp setpgsmain40008000
  675.  
  676.         if 1==0;EGA
  677. DrawTile_A_X2Y2DE
  678.         sla     D
  679.         sla     E
  680. DrawTile_A_XYDE
  681.         LD      H,a
  682.         LD      L,0
  683.         srl h
  684.         rr l
  685.         LD      bc,tilegfx
  686.         ADD     HL,bc
  687.         ex de,hl
  688. ;hl=xy
  689.         ld a,h ;x
  690.          add a,4
  691.         ;ld l,l ;y
  692.         ld h,0
  693.         ld b,h
  694.         ld c,l
  695.         add hl,hl
  696.         add hl,hl
  697.         add hl,bc ;*5
  698.          add hl,hl
  699.          add hl,hl
  700.          add hl,hl ;*40
  701.          add hl,hl
  702.          add hl,hl
  703.          add hl,hl
  704.         add a,l
  705.         ld l,a
  706.         ld a,h
  707.         adc a,0x40
  708.         ld h,a
  709.         ld bc,0x1008 ;b=hgt,c=wid (/2)
  710. ;de=gfx
  711. ;hl=scr
  712.         jp primgega
  713.         endif
  714.  
  715.        if EGA
  716. ;DrawSprite_Akeep_DExy
  717.         ;LD     (cursprite),A
  718. DrawSprite_A_DExy
  719. ;A=sprnum
  720. ;DE=xy
  721.         push bc
  722.         push de
  723.         push iy
  724.         add a,a
  725.         ld l,a
  726.         ld h,0xc0
  727.         call setpggfxc000
  728.         ld a,(hl)
  729.         ld ly,a
  730.         inc l
  731.         ld a,(hl)
  732.         ld hy,a
  733.         call setpgsscr40008000
  734.         ld c,e ;y
  735.         ld a,d ;x
  736.         srl a
  737.         add a,sprmaxwid-1
  738.         ld e,a
  739. ;e=x = -(sprmaxwid-1)..159 (ъюфшЁєхЄё  ъръ x+(sprmaxwid-1))
  740. ;c=y = -(sprmaxhgt-1)..199 (ъюфшЁєхЄё  ъръ хёЄ№)
  741.         call prspr
  742.         pop iy
  743.         call setpgcodec000
  744.         call setpgsmain40008000
  745.         pop de
  746.         pop bc
  747.         ret
  748.        endif
  749.  
  750.         include "prspr.asm"
  751.  
  752.         if EGA
  753. gettilebuf
  754.        ds 128
  755.         endif
  756.        if EGA
  757. GetTileToHL_DEXY
  758. ;hl=addr
  759. ;e=Y
  760. ;d=X
  761.         push bc
  762.         push de
  763.         sla d
  764.         sla d
  765.         sla d
  766.         sla e
  767.         sla e
  768.         sla e        
  769.         ld bc,0x1008 ;b=hgt,c=wid (/2)
  770.         jr GetBuf2CxB_DExy_ToHL
  771.        if 1==0
  772.        ld b,12*8
  773. gettilefake0
  774.        ld a,r
  775.        ld (hl),a
  776.        inc hl
  777.        djnz gettilefake0
  778.        pop de
  779.        pop bc
  780.        ret
  781.        endif
  782. GetBuf24x16_DExy
  783. ;e=y
  784. ;d=x
  785.         push bc
  786.         push de
  787.         ld bc,0x100c ;b=hgt,c=wid (/2)
  788.         ld hl,rebuf24x16
  789. GetBuf2CxB_DExy_ToHL
  790.         push hl ;gfx
  791.         ld a,d ;x
  792.         srl a
  793.         srl a
  794.         srl a
  795.          add a,4
  796.         ld l,e ;y
  797.         ld h,0
  798.         ld d,h
  799.         ld e,l
  800.         add hl,hl
  801.         add hl,hl
  802.         add hl,de ;*5
  803.          add hl,hl
  804.          add hl,hl
  805.          add hl,hl ;*40
  806.         add a,l
  807.         ld l,a
  808.         ld a,h
  809.         adc a,0x40
  810.         ld h,a
  811.         pop de ;gfx
  812. ;de=gfx
  813. ;hl=scr
  814.         push bc
  815.         call setpgsscr40008000
  816.         pop bc
  817. getimgega0
  818.         push bc
  819.         ld hx,b
  820.         push hl
  821.         ld bc,40
  822. getimgegacolumn0
  823.         ld a,(hl)
  824.         ld (de),a
  825.         inc de
  826.         add hl,bc
  827.         dec hx
  828.         jr nz,getimgegacolumn0
  829.         pop hl
  830.         ld a,0x9f;0xa0
  831.         cp h
  832.         ld bc,0x4000
  833.         adc hl,bc
  834.         jp pe,getimgegacolumn0q ;т яюыютшэх ёыєўрхт
  835. ;8000->ё000 (эрфю 6000) шыш a000->e001 (эрфю 4001)
  836.          inc a
  837.         xor h
  838.         ld h,a
  839. getimgegacolumn0q
  840.         pop bc
  841.         dec c
  842.         jr nz,getimgega0
  843.         call setpgsmain40008000
  844.         pop de
  845.         pop bc
  846.         ret
  847.  
  848. ReBuf24x16_DExy
  849. ;e=y
  850. ;d=x (width 16 if multiple of 8)
  851.         push bc
  852.         push de
  853.         ld bc,0x1008 ;b=hgt,c=wid (/2)
  854.         ld a,d
  855.         and 7
  856.         jr z,$+4
  857.          ld c,0x0c
  858.         ld a,d ;x
  859.         srl a
  860.         srl a
  861.         srl a
  862.          add a,4
  863.         ld l,e ;y
  864.         ld h,0
  865.         ld d,h
  866.         ld e,l
  867.         add hl,hl
  868.         add hl,hl
  869.         add hl,de ;*5
  870.          add hl,hl
  871.          add hl,hl
  872.          add hl,hl ;*40
  873.         add a,l
  874.         ld l,a
  875.         ld a,h
  876.         adc a,0x40
  877.         ld h,a
  878.         ld de,rebuf24x16
  879. ;de=gfx
  880. ;hl=scr
  881.         call primgega
  882.         pop de
  883.         pop bc
  884.         ret
  885.  
  886. buf24x16
  887.         ds 12*16
  888. buf24x16_2
  889.         ds 12*16
  890. gettilebuf2
  891.         ds 8*16
  892. rebuf24x16
  893.         ds 12*16
  894.        endif
  895.  
  896.        if EGA
  897. DrawSprite16x16_HL_DExy
  898. ;hl=gfx
  899. ;e=y
  900. ;d=x (pixel perfect!)
  901.         push bc
  902.         push de
  903.         ex de,hl
  904.         ld b,0
  905.         ld a,h ;x
  906.         srl a
  907.         ;ld l,l ;y
  908.         ld c,l
  909.         srl a ;x bit 0
  910.         ;ld h,0x40/32/2
  911.         ;jr nc,$+4 ;x bit 0
  912.         ; ld h,0x80/32/2
  913.          ld h,b;0
  914.          rl h
  915.          inc h ;0x40/32/2 шыш 0x80/32/2
  916.         srl a ;x bit 1
  917.          rl h
  918.         add hl,hl
  919.         add hl,hl
  920.         add hl,bc
  921.         add hl,hl
  922.         add hl,hl
  923.         add hl,hl ;y*40+scrbase
  924.          if scrbase&0xff
  925.          add a,scrbase&0xff
  926.          endif
  927. ;a=x/4
  928.         add a,l
  929.         ld l,a
  930.         adc a,h
  931.         sub l
  932.         ld h,a ;hl=scr
  933. ;de=gfx
  934. ;hl=scr
  935.         ld bc,0x1008 ;b=hgt,c=wid (/2)
  936.         call primgega
  937.         pop de
  938.         pop bc
  939.         ret
  940.        endif
  941.  
  942.        if EGA
  943. ClearTile_DExy
  944.         ;ret
  945. ;E=y
  946. ;D=x (width 24 if not multiple of 8)
  947.         push bc
  948.         push de
  949.         ld bc,0x1008 ;b=hgt,c=wid (/2)
  950.         ld a,d ;x
  951.         and 7
  952.         jr z,$+4
  953.          ld c,0x0c ;wid (/2)
  954.         ld a,d
  955.         srl a
  956.         srl a
  957.         srl a
  958.          add a,4
  959.         ld l,e ;y
  960.         ld h,0
  961.         ld d,h
  962.         ld e,l
  963.         add hl,hl
  964.         add hl,hl
  965.         add hl,de ;*5
  966.          add hl,hl
  967.          add hl,hl
  968.          add hl,hl ;*40
  969.         add a,l
  970.         ld l,a
  971.         ld a,h
  972.         adc a,0x40
  973.         ld h,a
  974.         ld de,zeros24x16
  975. ;de=gfx
  976. ;hl=scr
  977.         call primgega
  978.         pop de
  979.         pop bc
  980.         ret
  981. zeros24x16
  982.         ds 12*16
  983.        endif
  984.  
  985. readbmphead_pal
  986.         ld de,bgpush_bmpbuf
  987.         ld hl,14+2;54+(4*16)
  988. ;de=buf
  989. ;hl=size
  990.         call readstream_file
  991.         ld de,bgpush_bmpbuf
  992.         ld hl,(bgpush_bmpbuf+14)
  993.         dec hl
  994.         dec hl
  995. ;de=buf
  996. ;hl=size
  997.         call readstream_file
  998.         ld de,bgpush_bmpbuf
  999.         ld hl,+(4*16)
  1000. ;de=buf
  1001. ;hl=size
  1002.         call readstream_file
  1003.  
  1004.         ld hl,bgpush_bmpbuf;+54
  1005.         ld ix,pal
  1006.         ld b,16
  1007. recodepal0
  1008.         ld e,(hl)
  1009.         inc hl
  1010.         ld d,(hl)
  1011.         inc hl
  1012.         push hl
  1013.         ld l,(hl) ;e=B, d=G, l=R
  1014.         call readfile_rgbtopal
  1015.         pop hl
  1016.         inc hl
  1017.         inc hl
  1018.         djnz recodepal0
  1019.         ret
  1020.  
  1021.         macro RECOLOR
  1022.         ld a,(de)
  1023.         inc de
  1024.         ld ($+4),a
  1025.         ld a,(trecolor)
  1026.         ld (hl),a
  1027.         endm
  1028. readbmpscr
  1029.         ld hl,0x4000+(199*40)
  1030.         ld b,200
  1031. readbmpscr0
  1032.         push bc
  1033.         push hl
  1034.         ld de,bgpush_bmpbuf
  1035.         ld hl,320/2
  1036. ;de=buf
  1037. ;hl=size
  1038.         push de
  1039.         call readstream_file
  1040.         pop de
  1041.         pop hl
  1042.         push hl
  1043.         ld b,40
  1044. readbmpscr00        
  1045.         RECOLOR
  1046.         ld a,h
  1047.         add a,0x40
  1048.         ld h,a
  1049.         RECOLOR
  1050.         ld a,h
  1051.         add a,0x20-0x40
  1052.         ld h,a
  1053.         RECOLOR
  1054.         ld a,h
  1055.         add a,0x40
  1056.         ld h,a
  1057.         RECOLOR
  1058.         ld a,h
  1059.         sub 0x60
  1060.         ld h,a
  1061.         inc hl
  1062.         djnz readbmpscr00
  1063.         pop hl
  1064.         ld bc,-40
  1065.         add hl,bc
  1066.         pop bc
  1067.         djnz readbmpscr0
  1068.         ret
  1069.  
  1070. readfile_rgbtopal
  1071. ;e=B, d=G, l=R
  1072.         call calcRGBtopal_pp
  1073.         ld (ix+1),a
  1074.         call calcRGBtopal_pp
  1075.         ld (ix),a
  1076.         inc ix
  1077.         inc ix
  1078.         ret
  1079.  
  1080. calcRGBtopal_pp
  1081. ;e=B, d=G, l=R
  1082. ;DDp palette: %grbG11RB(low),%grbG11RB(high), ??oN????N
  1083.         xor a
  1084.         rl e  ;B
  1085.         rra
  1086.         rl l  ;R
  1087.         rra
  1088.         rrca
  1089.         rrca
  1090.         rl d  ;G
  1091.         rra
  1092.         rl e  ;b
  1093.         rra
  1094.         rl l  ;r
  1095.         rra
  1096.         rl d  ;g
  1097.         rra
  1098.         cpl
  1099.         ret
  1100.  
  1101. ;------------------
  1102. ; Keyboard scanning
  1103. ;------------------
  1104. ; from keyboard and s-inkey$
  1105. ; returns 1 or 2 keys in DE, most significant shift first if any
  1106. ; key values 0-39 else 255
  1107.  
  1108. ;; KEY-SCAN
  1109. L028E   LD      L,$2F           ; initial key value
  1110.                                 ; valid values are obtained by subtracting
  1111.                                 ; eight five times.
  1112.         LD      DE,$FFFF        ; a buffer for 2 keys.
  1113.  
  1114.         LD      BC,$FEFE        ; the commencing port address
  1115.                                 ; B holds 11111110 initially and is also
  1116.                                 ; used to count the 8 half-rows
  1117. ;; KEY-LINE
  1118. L0296   IN      A,(C)           ; read the port to A - bits will be reset
  1119.                                 ; if a key is pressed else set.
  1120.         CPL                     ; complement - pressed key-bits are now set
  1121.         AND     $1F             ; apply 00011111 mask to pick up the
  1122.                                 ; relevant set bits.
  1123.  
  1124.         JR      Z,L02AB         ; forward to KEY-DONE if zero and therefore
  1125.                                 ; no keys pressed in row at all.
  1126.  
  1127.         LD      H,A             ; transfer row bits to H
  1128.         LD      A,L             ; load the initial key value to A
  1129.  
  1130. ;; KEY-3KEYS
  1131. L029F   INC     D               ; now test the key buffer
  1132.         RET     NZ              ; if we have collected 2 keys already
  1133.                                 ; then too many so quit.
  1134.  
  1135. ;; KEY-BITS
  1136. L02A1   SUB     $08             ; subtract 8 from the key value
  1137.                                 ; cycling through key values (top = $27)
  1138.                                 ; e.g. 2F>   27>1F>17>0F>07
  1139.                                 ;      2E>   26>1E>16>0E>06
  1140.         SRL     H               ; shift key bits right into carry.
  1141.         JR      NC,L02A1        ; back to KEY-BITS if not pressed
  1142.                                 ; but if pressed we have a value (0-39d)
  1143.  
  1144.         LD      D,E             ; transfer a possible previous key to D
  1145.         LD      E,A             ; transfer the new key to E
  1146.         JR      NZ,L029F        ; back to KEY-3KEYS if there were more
  1147.                                 ; set bits - H was not yet zero.
  1148.  
  1149. ;; KEY-DONE
  1150. L02AB   DEC     L               ; cycles 2F>2E>2D>2C>2B>2A>29>28 for
  1151.                                 ; each half-row.
  1152.         RLC     B               ; form next port address e.g. FEFE > FDFE
  1153.         JR      C,L0296         ; back to KEY-LINE if still more rows to do.
  1154.  
  1155.         LD      A,D             ; now test if D is still FF ?
  1156.         INC     A               ; if it is zero we have at most 1 key
  1157.                                 ; range now $01-$28  (1-40d)
  1158.         RET     Z               ; return if one key or no key.
  1159.  
  1160.         CP      $28             ; is it capsshift (was $27) ?
  1161.         RET     Z               ; return if so.
  1162.  
  1163.         CP      $19             ; is it symbol shift (was $18) ?
  1164.         RET     Z               ; return also
  1165.  
  1166.         LD      A,E             ; now test E
  1167.         LD      E,D             ; but first switch
  1168.         LD      D,A             ; the two keys.
  1169.         CP      $18             ; is it symbol shift ?
  1170.         RET                     ; return (with zero set if it was).
  1171.                                 ; but with symbol shift now in D
  1172.  
  1173.  
  1174.         align 256
  1175. trecolor
  1176. ;%00003210 => %.3...210
  1177.         dup 256
  1178. _3=$&8
  1179. _210=$&7
  1180. _3L=($>>4)&8
  1181. _210L=($>>4)&7
  1182.         db (_3L*0x08) + (_210L*0x01) + (_3*0x10) + (_210*0x08)
  1183.         edup
  1184.  
  1185. bgpush_bmpbuf
  1186.         ds 320
  1187.  
  1188. res_path
  1189.         db "solkey",0
  1190. bmpfilename
  1191.         db "solkey.bmp",0
  1192.         include "../../_sdk/file.asm"
  1193.  
  1194.         ds 0x3f00-$
  1195.         ds 0x4000-$
  1196.         incbin "screen.scr"
  1197.         ;incbin "slabage/sprdata.bin"
  1198. ;tilegfx=$+0x8000
  1199.         ;incbin "slabage/tiles.bin"
  1200. ;panelgfx=$+0x8000
  1201.         ;incbin "slabage/panel.bin"
  1202.  
  1203.         ds 0x6600-$
  1204. L_6600
  1205.         incbin  "font.bin"
  1206.         ds 0x6880-$
  1207.         include "FILE.ASM"
  1208. end
  1209.  
  1210.         display "End=",end
  1211.         ;display "Free after end=",/d,#c000-end
  1212.         display "Size ",/d,end-begin," bytes"
  1213.         savebin "barbaria.com",begin,end-begin
  1214.         LABELSLIST "../../../us/user.l"
  1215.