Subversion Repositories NedoOS

Rev

Rev 804 | Rev 865 | 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. THESTACK=0x3d00
  15. INTSTACK=0x3c00
  16. tempsp=0x3c06 ;6 bytes for prspr
  17. ;UVSCROLL_SCRWID=320 ;8*(TILEMAPWID-2)
  18. ;UVSCROLL_SCRHGT=192 ;(фхышЄё  эр 16!!!) ;8*(TILEMAPHGT-2) ;ўЄюс√ т√тюфшЄ№ тёхуфр 12 ьхЄрЄрщыют (3 сыюър яю 8) яю т√ёюЄх
  19.  
  20. CODE            EQU $7BE0
  21.  
  22. ;*****************************************************************************
  23. ;** SPECTRUM MIDNIGHT RESISTANCE ALL IN ONE SOURCE                          **
  24. ;*****************************************************************************
  25.  
  26.                 ;OCMD "#SP 7BE0"
  27.                 ;OCMD "K0"
  28.  
  29. ;*****************************************************************************
  30.  
  31. MUSICALSO       EQU 0
  32.  
  33.                 IF MUSICALSO=1
  34. STARTLEV        EQU 0
  35.                 ENDIF
  36.  
  37.                 IF MUSICALSO=0
  38. STARTLEV        EQU 1
  39. AUTO            EQU 1 ; ORIG = EQU 0
  40.                 ENDIF
  41.  
  42.                 ;IF STARTLEV=1
  43.                 ;org #4000
  44.                 ;insert "midnight.scr"
  45.                 ;ENDIF
  46.  
  47.                 IF MUSICALSO=0
  48.  
  49. STARTLIVES      EQU 6-1
  50.  
  51. INFLIF          EQU 0             ;255
  52. INFAMM          EQU 0             ;255
  53. WEPSEL          EQU 0             ;255
  54. SPACETOKILL     EQU 0             ;255
  55.  
  56. ;*****************************************************************************
  57. ;** MEMORY MAP                                                              **
  58. ;*****************************************************************************
  59.  
  60. BACKSCR         EQU $5B00               ; REAL COPYS
  61. BACKATR         EQU BACKSCR+($100*16)
  62. BACKEND         EQU BACKATR+($20*16)
  63. BACKLEN         EQU BACKEND-BACKSCR
  64.  
  65. BACKSCR2        EQU BACKEND             ; BACK SCREEN (COPY TO BACKSCR)
  66. BACKATR2        EQU BACKSCR2+($D0*16)
  67. BACKEND2        EQU BACKATR2+($1A*16)
  68. BACKLEN2        EQU BACKEND2-BACKSCR2
  69.  
  70. MENUSTART       EQU $7000               ; MENU ROUTINES + CHEAT MODE ROUTINE
  71. ;THESTACK        EQU $7BE0
  72. ;CODE            EQU $7BE0
  73.  
  74. MIRPAGE         EQU $FD00               ; FD00 - FDFF
  75. INTPAGE         EQU $FE00               ; FE00 - FF00
  76. PAGE0           EQU $FF01               ; FF01 - FFF0
  77. INTJP           EQU $FFF4               ; FFF4 - FFFF
  78.  
  79. MUSRESETSOUND   EQU $E000
  80. MUSDOMUSIC      EQU $E003
  81. MUSINITTUNE     EQU $E006
  82.  
  83. ;***************************************
  84. ;** EQUATES                           **
  85. ;***************************************
  86.  
  87. ;PRHEX8          EQU 5
  88. ;PRHEX16         EQU 6
  89. PRKEY           EQU 7
  90. PRCLS           EQU 12
  91. PRFONT          EQU 14
  92. PRMULTY         EQU 15
  93. PRINK           EQU 16
  94. PRSIZE          EQU 17
  95. PRGAMECLS       EQU 18
  96. PRPAUSE         EQU 19
  97. PRINK2          EQU 20
  98. PRAT            EQU 22
  99. PREOF           EQU 255
  100.  
  101. KEYB            EQU 0
  102. KEMP            EQU 1
  103. FACE            EQU 2
  104. CURS            EQU 3
  105. CONT            EQU FACE
  106.  
  107. POKE            EQU $80                   ; POKE ADDRESS, VALUE (MAP DATA)
  108.  
  109. HIGHTUNE        EQU 9
  110.  
  111. ;***************************************
  112.  
  113. NOBUL           EQU 32
  114. BULX            EQU 0
  115. BULY            EQU 1
  116. BULP            EQU 2
  117. BULT            EQU 3
  118. BULLEN          EQU 4
  119.  
  120. NOEXP           EQU 8
  121. EXPX            EQU 0
  122. EXPY            EQU 1
  123. EXPP            EQU 2
  124. EXPLEN          EQU 3
  125.  
  126. NOFLAMES        EQU 10
  127.  
  128. NOBAD           EQU 12
  129. XPOS            EQU 0
  130. YPOS            EQU 1
  131. TYPE            EQU 2
  132. PHASE           EQU 3
  133. ACTION          EQU 4
  134. COUNT           EQU 5
  135. TEMP            EQU 6
  136. BADLEN          EQU 7
  137.  
  138. JUMPBIT         EQU 0
  139. KEYBIT          EQU 1
  140.  
  141. JUMP            EQU 1
  142. KEY             EQU 2
  143.  
  144. FIN             EQU 255
  145.  
  146.                 ENDIF
  147.  
  148. ;screenYtable=0x8b00
  149.  
  150. EGA=1
  151.         ;slot 3
  152.         ;page 0
  153.         org PROGSTART
  154. begin
  155.         jp begin2 ;/prsprqwid (sprites in file are made so that they return here)
  156. begin2
  157.         ld sp,STACK
  158.         OS_HIDEFROMPARENT
  159.  
  160.         ld e,3+8+0x80 ;6912+noturbo+keep
  161.         OS_SETGFX ;e=0:EGA, e=2:MC, e=3:6912, e=6:text ;+SET FOCUS ;e=-1: disable gfx (out: e=old gfxmode)
  162.  
  163.         ;ld e,1
  164.         ;OS_SETSCREEN
  165.         ld e,0 ;color byte
  166.         OS_CLS
  167.         ;ld e,0
  168.         ;OS_SETSCREEN
  169.         ;ld e,0 ;color byte
  170.         ;OS_CLS
  171.  
  172.         OS_GETMAINPAGES
  173. ;dehl=pages in 0000,4000,8000,c000
  174.         ld a,e
  175.         ld (pggfx),a
  176.         ld a,h
  177.         ld (pgcode8000),a
  178.         ld a,l
  179.         ld (pgcodec000),a
  180.         ;jr $
  181.         ;OS_NEWPAGE
  182.         ;ld a,e
  183.         ld (tpgs+0),a
  184.         OS_NEWPAGE
  185.         ld a,e
  186.         ld (tpgs+1),a
  187.         OS_NEWPAGE
  188.         ld a,e
  189.         ld (tpgs+3),a
  190.         OS_NEWPAGE
  191.         ld a,e
  192.         ld (tpgs+4),a
  193.         OS_NEWPAGE
  194.         ld a,e
  195.         ld (tpgs+6),a
  196.         OS_NEWPAGE
  197.         ld a,e
  198.         ld (tpgs+7),a
  199.  
  200.         OS_NEWPAGE
  201.         ld a,e
  202.         ld (pgmain4000),a
  203.  
  204.         if 1==0
  205.         ld de,res_path
  206.         OS_CHDIR
  207.  
  208.         call setpgsscr40008000
  209.  
  210.         ld de,emptypal
  211.         OS_SETPAL
  212.         ld de,bmpfilename
  213.         call openstream_file
  214.         call readbmphead_pal
  215.         call readbmpscr
  216.         call closestream_file
  217.         ld de,pal
  218.         OS_SETPAL
  219.        
  220.         call setpgsmain40008000
  221.  
  222.         ;ld b,50
  223.         ;halt
  224.         ;djnz $-1
  225.         YIELDGETKEYLOOP
  226.  
  227.         ld e,3+8+0x80 ;6912+noturbo+keep
  228.         OS_SETGFX ;e=0:EGA, e=2:MC, e=3:6912, e=6:text ;+SET FOCUS ;e=-1: disable gfx (out: e=old gfxmode)
  229.         ld e,0 ;color byte
  230.         OS_CLS
  231.         ld de,standardpal
  232.         OS_SETPAL
  233.         YIELD
  234.         endif
  235.  
  236.         ld de,res_path
  237.         OS_CHDIR
  238.         ld de,muzfilename
  239.         call openstream_file
  240.         ld a,7
  241.         call setpg
  242.         ld de,music
  243.         ld hl,music_sz
  244.         call readstream_file
  245.         call closestream_file
  246.        
  247.         ld hl,levelfilenames
  248. loadlevels0
  249.         ld a,(hl) ;pg
  250.         inc hl
  251.         cp -1
  252.         jr z,loadlevels0q
  253.         call setpg
  254.         ld e,(hl)
  255.         inc hl
  256.         ld d,(hl)
  257.         inc hl
  258.         push hl
  259.         push de ;addr
  260.         ex de,hl
  261.         call openstream_file
  262.         pop de
  263.         ld hl,0x2000
  264.         call readstream_file
  265.         call closestream_file
  266.         pop hl
  267.         xor a
  268.         ld b,a
  269.         ld c,a
  270.         cpir ;hl=after #0
  271.         jr loadlevels0
  272. loadlevels0q
  273.  
  274.         if 1==1
  275.         ld a,(user_scr0_high) ;ok
  276.         SETPG32KLOW
  277.         ld hl,0x4000
  278.         ld de,0x4000+0x4000
  279.         ld bc,0x4000
  280.         ldir
  281.         ;ld a,(user_scr0_high)
  282.         SETPG16K
  283.         ld a,(pgcode8000)
  284.         SETPG32KLOW
  285.         endif
  286.         ld a,(user_scr0_high) ;ok
  287.         SETPG16K
  288.        
  289.         call swapimer
  290.  
  291.         if EGA
  292.         ld hl,prsprqwid
  293.         ld (0x0101),hl ;sprites in file are made so that they return in 0x0100
  294.         endif
  295.  
  296.         YIELDGETKEYLOOP
  297.        
  298.         ;jr $
  299.         xor a
  300.         call setpg
  301.         jp START;GO
  302.  
  303. setpg
  304.         push bc
  305.         and 7
  306.          cp 2
  307.          jr z,$
  308.          cp 5
  309.          jr z,$
  310.         ld ($+4),a
  311.         ld a,(tpgs)
  312.         SETPG32KHIGH
  313.         pop bc
  314.         ret
  315.  
  316.         align 256
  317. tpgs
  318.         ds 256
  319.  
  320.         ;include "pal.ast" ;slabpal
  321. standardpal
  322.         STANDARDPAL
  323. pal
  324.         ds 32,0xff
  325. emptypal
  326.         ds 32,0xff
  327.  
  328. jphl
  329.         jp (hl)
  330.  
  331. CheckBreak
  332.         ld a,0xfe
  333.         in a,(0xfe)
  334.         rra
  335.         ret c
  336.         ld a,0x7f
  337.         in a,(0xfe)
  338.         rra
  339.         ret
  340. ReadKeysCheckQuit
  341.         call CheckBreak
  342.         jp c,READKEYS ;ret c
  343. quiter
  344.         if 1==0
  345.         halt
  346. pgmuznum=$+1
  347.         ld a,0
  348.         SETPG32KHIGH
  349.           ld hl,muz
  350.           OS_SETMUSIC
  351.         halt
  352.         endif
  353.         call swapimer
  354.         im 1
  355.         call killmuz ;because we played music not by OS
  356.         QUIT
  357.  
  358. killmuz
  359.         ld a,0xfe
  360.         call shut1ay
  361.         ld a,0xff
  362. shut1ay
  363.         ld bc,0xfffd
  364.         out (c),a
  365.         ld de,0x0e00
  366. shutay0
  367.         dec d
  368.         ld b,0xff
  369.         out (c),d
  370.         ld b,0xbf
  371.         out (c),e
  372.         jr nz,shutay0
  373.         ret
  374.  
  375. redattr_killable2b
  376.         dw 0
  377.  
  378. ;L_5B00 ;= #5b00
  379. ;        db 0
  380.  
  381. setpggfxc000
  382. pggfx=$+1
  383.         ld a,0
  384.         SETPG32KHIGH
  385.         ret
  386. setpgcodec000
  387. pgcodec000=$+1
  388.         ld a,0
  389.         SETPG32KHIGH
  390.         ret
  391.  
  392. swapimer
  393.         di
  394.         ld de,0x0038
  395.         ld hl,oldimer
  396.         ld bc,3
  397. swapimer0
  398.         ld a,(de)
  399.         ldi ;[oldimer] -> [0x0038]
  400.         dec hl
  401.         ld (hl),a ;[0x0038] -> [oldimer]
  402.         inc hl
  403.         jp pe,swapimer0
  404.         ei
  405.         ret
  406. oldimer
  407.         jp on_int ;чрьхэшЄё  эр ъюф шч 0x0038
  408.         jp 0x0038+3    
  409.  
  410. reter
  411.         ret
  412.  
  413. tstarttime       DB       #00,#00,#00
  414. curgametimer       DB       #00,#00,#00
  415. stoptimer       DB       #00
  416. curtimerlow       DB       #00
  417. ;
  418. on_int
  419. ;restore stack with de
  420.         EX DE,HL
  421.         EX (SP),HL ;de="hl", stack contains "de"
  422.         LD (on_int_jp),HL
  423.         LD (on_int_sp),SP
  424.         LD SP,INTSTACK
  425.         push af
  426.         push bc
  427.         push de ;"hl"
  428.         exx
  429.         ex af,af' ;'
  430.         push af
  431.         push bc
  432.         push de
  433.         push hl
  434.         push ix
  435.         push iy
  436.          ld a,(curpg16k) ;ok
  437.          push af
  438.          ld a,(curpg32klow) ;ok
  439.          push af
  440.          call setpgsmain40008000
  441.         ;DI
  442. ;curscrnum_int=$+1
  443. ;        ld e,0
  444. ;        OS_SETSCREEN
  445.         call INTS
  446.         call oldimer ;ei
  447.          GET_KEY
  448.          jr nz,Imer_nofocus
  449.          ;ld a,(user_scr0_high) ;ok
  450.          ;SETPG16K ;TODO redraw screen when retake focus???
  451. Imer_nofocus
  452.         ;LD     A,(stoptimer)
  453.         ;OR     A
  454.         ;CALL   Z,DecTimer
  455.          pop af
  456.          SETPG32KLOW
  457.          pop af
  458.          SETPG16K
  459.         pop iy
  460.         pop ix
  461.         pop hl
  462.         pop de
  463.         pop bc
  464.         pop af
  465.         ex af,af' ;'
  466.         exx
  467.         pop hl
  468.         pop bc
  469.         pop af        
  470. on_int_sp=$+1
  471.         ld sp,0
  472.         pop de
  473.         ei
  474. on_int_jp=$+1
  475.         jp 0
  476. ;
  477. ;
  478. RIGHTPIX=0x38;0xb8;%10111000
  479. LEFTPIX=0x07;0x47;%01000111
  480.         macro FONTBYTE
  481.         ld a,(de)
  482.         ld c,a
  483.         xor a
  484.         rl c
  485.         jr nc,$+4
  486.          or LEFTPIX
  487.         rl c
  488.         jr nc,$+4
  489.          or RIGHTPIX
  490.         ld (hl),a
  491.         ld a,h
  492.         add a,0x40
  493.         ld h,a
  494.         xor a
  495.         rl c
  496.         jr nc,$+4
  497.          or LEFTPIX
  498.         rl c
  499.         jr nc,$+4
  500.          or RIGHTPIX
  501.         ld (hl),a
  502.         ld a,h
  503.         add a,0x20-0x40
  504.         ld h,a
  505.         xor a
  506.         rl c
  507.         jr nc,$+4
  508.          or LEFTPIX
  509.         rl c
  510.         jr nc,$+4
  511.          or RIGHTPIX
  512.         ld (hl),a
  513.         ld a,h
  514.         add a,0x40
  515.         ld h,a
  516.         xor a
  517.         rl c
  518.         jr nc,$+4
  519.          or LEFTPIX
  520.         rl c
  521.         jr nc,$+4
  522.          or RIGHTPIX
  523.         ld (hl),a
  524.         endm
  525.  
  526. PrintCharA_EGA
  527.         push bc
  528.         push de
  529.         push hl
  530.        push af
  531.         call setpgsscr40008000
  532.         LD      DE,(curprintyx)
  533.         sla e
  534.         sla e
  535.         sla e
  536.         ld a,d ;x
  537.          add a,4
  538.         ld l,e ;y
  539.         ld h,0
  540.         ld d,h
  541.         ld e,l
  542.         add hl,hl
  543.         add hl,hl
  544.         add hl,de ;*5
  545.          add hl,hl
  546.          add hl,hl
  547.          add hl,hl ;*40
  548.         add a,l
  549.         ld l,a
  550.         ld a,h
  551.         adc a,0x40
  552.         ld h,a
  553.        pop af
  554.         PUSH    HL
  555.         LD      DE,font-256;L_BE02
  556.         LD      H,#00
  557.         LD      L,A
  558.         ADD     HL,HL
  559.         ADD     HL,HL
  560.         ADD     HL,HL
  561.         ADD     HL,DE
  562.         EX      DE,HL
  563.         POP     HL
  564.         LD      hx,#08
  565.  
  566. PrintCharA_EGA0
  567.         FONTBYTE
  568.         ld bc,40-0x6000
  569.         add hl,bc
  570.         INC     DE
  571.         dec hx
  572.         jr nz,PrintCharA_EGA0
  573.        
  574.         LD      DE,(curprintyx)
  575.         INC     D
  576.         LD      A,D
  577.         CP      #20
  578.         JR      NZ,PrintCharA_EGAq
  579.         INC     E
  580.         LD      D,#00
  581.         LD      A,E
  582.         CP      #18
  583.         JR      NZ,PrintCharA_EGAq
  584.         LD      E,#00
  585. PrintCharA_EGAq
  586.         LD      (curprintyx),DE
  587.         call setpgsmain40008000
  588.         pop hl
  589.         pop de
  590.         pop bc
  591.         ret
  592.        
  593. PrintCharA
  594.         PUSH    DE
  595.         PUSH    HL
  596.         PUSH    BC
  597.         PUSH    AF
  598.         LD      DE,(curprintyx)
  599.         LD      A,E
  600.         AND     #18
  601.         OR      #40
  602.         LD      H,A
  603.         LD      A,E
  604.         AND     #07
  605.         OR      A
  606.         RRA
  607.         RRA
  608.         RRA
  609.         RRA
  610.         ADD     A,D
  611.         LD      L,A
  612.         POP     AF
  613.         PUSH    HL
  614.         LD      DE,font-256;L_BE02
  615.         LD      H,#00
  616.         LD      L,A
  617.         ADD     HL,HL
  618.         ADD     HL,HL
  619.         ADD     HL,HL
  620.         ADD     HL,DE
  621.         EX      DE,HL
  622.         POP     HL
  623.         LD      B,#08
  624. L_C6EB  LD      A,(DE)
  625.         LD      (HL),A
  626.         INC     H
  627.         INC     DE
  628.         DJNZ    L_C6EB
  629.         LD      DE,(curprintyx)
  630.         INC     D
  631.         LD      A,D
  632.         CP      #20
  633.         JR      NZ,L_C705
  634.         INC     E
  635.         LD      D,#00
  636.         LD      A,E
  637.         CP      #18
  638.         JR      NZ,L_C705
  639.         LD      E,#00
  640. L_C705  LD      (curprintyx),DE
  641.         POP     BC
  642.         POP     HL
  643.         POP     DE
  644.         RET
  645. ;
  646. curprintyx       DW       #0000
  647. ;
  648. PrintStringHL
  649.         LD      A,(HL)
  650.         OR      A
  651.         RET     Z
  652.         CP      #16
  653.         JR      Z,L_C71C
  654.         CALL    PrintCharA
  655.         INC     HL
  656.         JR      PrintStringHL
  657. L_C71C  INC     HL
  658.         LD      E,(HL)
  659.         INC     HL
  660.         LD      D,(HL)
  661.         INC     HL
  662.         LD      (curprintyx),DE
  663.         JR      PrintStringHL
  664. ;
  665. PrintStringHL_EGA
  666.         LD      A,(HL)
  667.         OR      A
  668.         RET     Z
  669.         CP      #16
  670.         JR      Z,L_C71C_EGA
  671.         CALL    PrintCharA_EGA
  672.         INC     HL
  673.         JR      PrintStringHL_EGA
  674. L_C71C_EGA
  675.         INC     HL
  676.         LD      E,(HL)
  677.         INC     HL
  678.         LD      D,(HL)
  679.         INC     HL
  680.         LD      (curprintyx),DE
  681.         JR      PrintStringHL_EGA
  682.  
  683. font
  684.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  685.        DB       #00,#18,#3C,#18,#00,#18,#18,#00       ;..<.....
  686.        DB       #00,#36,#36,#6C,#00,#00,#00,#00       ;.66l....
  687.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  688.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  689.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  690.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  691.        DB       #00,#1C,#38,#00,#00,#00,#00,#00       ;..8.....
  692.        DB       #00,#0E,#1C,#1C,#1C,#1C,#0E,#00       ;........
  693.        DB       #00,#70,#38,#38,#38,#38,#70,#00       ;.p8888p.
  694.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  695.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  696.        DB       #00,#00,#00,#00,#00,#18,#18,#30       ;.......0
  697.        DB       #00,#00,#00,#3C,#3C,#00,#00,#00       ;...<<...
  698.        DB       #00,#00,#00,#00,#00,#18,#18,#00       ;........
  699.        DB       #00,#06,#0E,#1C,#38,#70,#60,#00       ;....8p`.
  700.        DB       #00,#3C,#72,#76,#7A,#72,#3C,#00       ;.<rvzr<.
  701.        DB       #00,#1C,#3C,#1C,#1C,#1C,#7E,#00       ;..<...~.
  702.        DB       #00,#7C,#0E,#0E,#3C,#70,#7E,#00       ;.|..<p~.
  703.        DB       #00,#7C,#0E,#3C,#0E,#0E,#7C,#00       ;.|.<..|.
  704.        DB       #00,#4E,#4E,#4E,#3E,#0E,#0E,#00       ;.NNN>...
  705.        DB       #00,#7C,#60,#7C,#0E,#0E,#7C,#00       ;.|`|..|.
  706.        DB       #00,#3C,#70,#7C,#72,#72,#3C,#00       ;.<p|rr<.
  707.        DB       #00,#7E,#06,#0E,#1C,#18,#18,#00       ;.~......
  708.        DB       #00,#3C,#72,#3C,#72,#72,#3C,#00       ;.<r<rr<.
  709.        DB       #00,#3C,#4E,#4E,#3E,#0E,#3C,#00       ;.<NN>.<.
  710.        DB       #00,#18,#18,#00,#00,#18,#18,#00       ;........
  711.        DB       #00,#18,#18,#00,#00,#18,#18,#30       ;.......0
  712.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  713.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  714.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  715.        DB       #7C,#0E,#0E,#0E,#1C,#00,#18,#00       ;|.......
  716.        DB       #00,#00,#00,#00,#00,#00,#00,#00       ;........
  717.        DB       #00,#3C,#72,#72,#7E,#72,#72,#00       ;.<rr~rr.
  718.        DB       #00,#7C,#72,#7C,#72,#72,#7C,#00       ;.|r|rr|.
  719.        DB       #00,#3E,#70,#70,#70,#70,#3E,#00       ;.>pppp>.
  720.        DB       #00,#7C,#72,#72,#72,#72,#7C,#00       ;.|rrrr|.
  721.        DB       #00,#3E,#70,#7C,#70,#70,#3E,#00       ;.>p|pp>.
  722.        DB       #00,#3E,#70,#7C,#70,#70,#70,#00       ;.>p|ppp.
  723.        DB       #00,#3E,#70,#70,#76,#72,#3C,#00       ;.>ppvr<.
  724.        DB       #00,#72,#72,#7E,#72,#72,#72,#00       ;.rr~rrr.
  725.        DB       #00,#7F,#1C,#1C,#1C,#1C,#7F,#00       ;........
  726.        DB       #00,#0E,#0E,#0E,#4E,#4E,#3C,#00       ;....NN<.
  727.        DB       #00,#72,#72,#7C,#72,#72,#72,#00       ;.rr|rrr.
  728.        DB       #00,#70,#70,#70,#70,#70,#3E,#00       ;.ppppp>.
  729.        DB       #00,#3E,#75,#75,#75,#75,#75,#00       ;.>uuuuu.
  730.        DB       #00,#7C,#72,#72,#72,#72,#72,#00       ;.|rrrrr.
  731.        DB       #00,#3C,#72,#72,#72,#72,#3C,#00       ;.<rrrr<.
  732.        DB       #00,#7C,#72,#72,#7C,#70,#70,#00       ;.|rr|pp.
  733.        DB       #00,#3C,#72,#72,#72,#7A,#3C,#08       ;.<rrrz<.
  734.        DB       #00,#7C,#72,#72,#7C,#72,#72,#00       ;.|rr|rr.
  735.        DB       #00,#3C,#70,#3C,#0E,#0E,#7C,#00       ;.<p<..|.
  736.        DB       #00,#7F,#1C,#1C,#1C,#1C,#1C,#00       ;........
  737.        DB       #00,#72,#72,#72,#72,#72,#3C,#00       ;.rrrrr<.
  738.        DB       #00,#72,#72,#72,#72,#34,#18,#00       ;.rrrr4..
  739.        DB       #00,#71,#71,#75,#75,#75,#3E,#00       ;.qquuu>.
  740.        DB       #00,#72,#72,#3C,#72,#72,#72,#00       ;.rr<rrr.
  741.        DB       #00,#4E,#4E,#4E,#3E,#0E,#3C,#00       ;.NNN>.<.
  742.        DB       #00,#7E,#0E,#1C,#38,#70,#7E,#00       ;.~..8p~.
  743.        DB       #00,#1E,#1C,#1C,#1C,#1C,#1E,#00       ;........
  744.        DB       #00,#60,#70,#38,#1C,#0E,#06,#00       ;.`p8....
  745.        DB       #00,#78,#38,#38,#38,#38,#78,#00       ;.x8888x.
  746.        DB       #00,#08,#1C,#3E,#5D,#1C,#1C,#00       ;...>]...
  747.        DB       #00,#78,#38,#3C,#3A,#3A,#3C,#00       ;.x8<::<.
  748.        DB       #00,#76,#79,#79,#79,#79,#76,#00       ;.vyyyyv.
  749.        DB       #00,#3C,#72,#72,#7E,#72,#72,#00       ;.<rr~rr.
  750.        DB       #00,#7C,#70,#7C,#72,#72,#7C,#00       ;.|p|rr|.
  751.        DB       #00,#4E,#4E,#4E,#4E,#4E,#3E,#02       ;.NNNNN>.
  752.        DB       #00,#1E,#2E,#2E,#2E,#2E,#7E,#42       ;......~B
  753.        DB       #00,#3E,#70,#7C,#70,#70,#3E,#00       ;.>p|pp>.
  754.        DB       #00,#3E,#5D,#5D,#3E,#1C,#1C,#00       ;.>]]>...
  755.        DB       #00,#3E,#70,#70,#70,#70,#70,#00       ;.>ppppp.
  756.        DB       #00,#72,#72,#3C,#72,#72,#72,#00       ;.rr<rrr.
  757.        DB       #00,#72,#72,#76,#7A,#72,#72,#00       ;.rrvzrr.
  758.        DB       #08,#72,#72,#76,#7A,#72,#72,#00       ;.rrvzrr.
  759.        DB       #00,#72,#72,#7C,#72,#72,#72,#00       ;.rr|rrr.
  760.        DB       #00,#3E,#4E,#4E,#4E,#4E,#4E,#00       ;.>NNNNN.
  761.        DB       #00,#71,#7B,#75,#71,#71,#71,#00       ;.q{uqqq.
  762.        DB       #00,#72,#72,#7E,#72,#72,#72,#00       ;.rr~rrr.
  763.        DB       #00,#3C,#72,#72,#72,#72,#3C,#00       ;.<rrrr<.
  764.        DB       #00,#7E,#4E,#4E,#4E,#4E,#4E,#00       ;.~NNNNN.
  765.        DB       #00,#3E,#4E,#4E,#3E,#4E,#4E,#00       ;.>NN>NN.
  766.        DB       #00,#7C,#72,#72,#7C,#70,#70,#00       ;.|rr|pp.
  767.        DB       #00,#3E,#70,#70,#70,#70,#3E,#00       ;.>pppp>.
  768.        DB       #00,#7F,#1C,#1C,#1C,#1C,#1C,#00       ;........
  769.        DB       #00,#4E,#4E,#4E,#3E,#0E,#3C,#00       ;.NNN>.<.
  770.        DB       #00,#5D,#5D,#3E,#5D,#5D,#5D,#00       ;.]]>]]].
  771.        DB       #00,#7C,#72,#7C,#72,#72,#7C,#00       ;.|r|rr|.
  772.        DB       #00,#70,#70,#7C,#72,#72,#7C,#00       ;.pp|rr|.
  773.        DB       #00,#72,#72,#7C,#72,#72,#7C,#00       ;.rr|rr|.
  774.        DB       #00,#7C,#0E,#3C,#0E,#0E,#7C,#00       ;.|.<..|.
  775.        DB       #00,#75,#75,#75,#75,#75,#3E,#00       ;.uuuuu>.
  776.        DB       #00,#7C,#0E,#3E,#0E,#0E,#7C,#00       ;.|.>..|.
  777.        DB       #00,#75,#75,#75,#75,#75,#3F,#01       ;.uuuuu?.
  778.        DB       #00,#4E,#4E,#4E,#3E,#0E,#0E,#00       ;.NNN>...
  779.        DB       #00,#00,#3E,#70,#70,#3E,#00,#00       ;..>pp>..
  780.  
  781. copypage
  782. ;hl=from
  783. ;de=to
  784. ;bc=size
  785. ;hx=frompg
  786. ;lx=topg
  787.         push bc
  788.         ld a,hx ;frompg
  789.         and 7
  790.         ld ($+4),a
  791.         ld a,(tpgs)
  792.         SETPG16K
  793.         ld a,lx ;to
  794.         and 7
  795.         ld ($+4),a
  796.         ld a,(tpgs)
  797.         SETPG32KLOW
  798.         pop bc
  799.         res 7,h
  800.         res 6,d
  801.         ldir
  802.         jp setpgsmain40008000
  803.  
  804. setpgsmain40008000
  805. pgmain4000=$+1
  806.         ld a,0
  807.         ld a,(user_scr0_high) ;ok
  808.         SETPG16K
  809. pgcode8000=$+1
  810.         ld a,0
  811.         SETPG32KLOW
  812.         ret
  813.  
  814. setpgsscr40008000;_current
  815.         call getuser_scr_low_cur
  816.         SETPG16K
  817.         call getuser_scr_high_cur
  818.         SETPG32KLOW
  819.         ret
  820.  
  821.         if 1==0
  822. setpgsscr40008000
  823.         call getuser_scr_low
  824.         SETPG16K
  825.         call getuser_scr_high
  826.         SETPG32KLOW
  827.         ret
  828.         endif
  829.  
  830. getuser_scr_low
  831. getuser_scr_low_patch=$+1
  832. getuser_scr_low_patchN=0xff&(user_scr0_low^user_scr1_low)
  833.         ld a,(user_scr1_low) ;ok
  834.         ret
  835.  
  836. getuser_scr_high
  837. getuser_scr_high_patch=$+1
  838. getuser_scr_high_patchN=0xff&(user_scr0_high^user_scr1_high)
  839.         ld a,(user_scr1_high) ;ok
  840.         ret
  841.  
  842. getuser_scr_low_cur
  843. getuser_scr_low_cur_patch=$+1
  844. getuser_scr_low_cur_patchN=0xff&(user_scr0_low^user_scr1_low)
  845.         ld a,(user_scr0_low) ;ok
  846.         ret
  847.  
  848. getuser_scr_high_cur
  849. getuser_scr_high_cur_patch=$+1
  850. getuser_scr_high_cur_patchN=0xff&(user_scr0_high^user_scr1_high)
  851.         ld a,(user_scr0_high) ;ok
  852.         ret
  853.  
  854. changescrpg_current
  855.         ld hl,getuser_scr_low_patch
  856.         ld a,(hl)
  857.         xor getuser_scr_low_patchN
  858.         ld (hl),a
  859.         ld hl,getuser_scr_high_patch
  860.         ld a,(hl)
  861.         xor getuser_scr_high_patchN
  862.         ld (hl),a
  863.         ld hl,getuser_scr_low_cur_patch
  864.         ld a,(hl)
  865.         xor getuser_scr_low_cur_patchN
  866.         ld (hl),a
  867.         ld hl,getuser_scr_high_cur_patch
  868.         ld a,(hl)
  869.         xor getuser_scr_high_cur_patchN
  870.         ld (hl),a
  871.  
  872.         ld a,1
  873. curscrnum=$+1
  874.         xor 0
  875.         ld ($-1),a
  876.         ret
  877.        
  878.         if 1==0
  879. changescrpg
  880.         call changescrpg_current
  881.         ld (curscrnum_int),a
  882.         ret
  883.         endif
  884.  
  885. primgega
  886. ;b=hgt,c=wid (/2)
  887. ;de=gfx
  888. ;hl=scr
  889.         push bc
  890.         call setpgsscr40008000
  891.         call setpggfxc000
  892.         pop bc
  893. primgega0
  894.         push bc
  895.         ld hx,b
  896.         push hl
  897.         ld bc,40
  898. primgegacolumn0
  899.         ld a,(de)
  900.         inc de
  901.         ld (hl),a
  902.         add hl,bc
  903.         dec hx
  904.         jr nz,primgegacolumn0
  905.         pop hl
  906.         ld a,0x9f;0xa0
  907.         cp h
  908.         ld bc,0x4000
  909.         adc hl,bc
  910.         jp pe,primgegacolumn0q ;т яюыютшэх ёыєўрхт
  911. ;8000->ё000 (эрфю 6000) шыш a000->e001 (эрфю 4001)
  912.          inc a
  913.         xor h
  914.         ld h,a
  915. primgegacolumn0q
  916.         pop bc
  917.         dec c
  918.         jr nz,primgega0
  919.         call setpgcodec000
  920.         jp setpgsmain40008000
  921.  
  922. clsega
  923.         call setpgsscr40008000
  924.         ld hl,0x4000
  925.         ld de,0x4001
  926.         ld bc,0x7fff
  927.         ld (hl),l;0
  928.         ldir
  929.         jp setpgsmain40008000
  930.  
  931.         if 1==0;EGA
  932. DrawTile_A_X2Y2DE
  933.         sla     D
  934.         sla     E
  935. DrawTile_A_XYDE
  936.         LD      H,a
  937.         LD      L,0
  938.         srl h
  939.         rr l
  940.         LD      bc,tilegfx
  941.         ADD     HL,bc
  942.         ex de,hl
  943. ;hl=xy
  944.         ld a,h ;x
  945.          add a,4
  946.         ;ld l,l ;y
  947.         ld h,0
  948.         ld b,h
  949.         ld c,l
  950.         add hl,hl
  951.         add hl,hl
  952.         add hl,bc ;*5
  953.          add hl,hl
  954.          add hl,hl
  955.          add hl,hl ;*40
  956.          add hl,hl
  957.          add hl,hl
  958.          add hl,hl
  959.         add a,l
  960.         ld l,a
  961.         ld a,h
  962.         adc a,0x40
  963.         ld h,a
  964.         ld bc,0x1008 ;b=hgt,c=wid (/2)
  965. ;de=gfx
  966. ;hl=scr
  967.         jp primgega
  968.         endif
  969.  
  970.        if EGA
  971. ;DrawSprite_Akeep_DExy
  972.         ;LD     (cursprite),A
  973. DrawSprite_A_DExy
  974. ;A=sprnum
  975. ;DE=xy
  976.         push bc
  977.         push de
  978.         push iy
  979.         add a,a
  980.         ld l,a
  981.         ld h,0xc0
  982.         call setpggfxc000
  983.         ld a,(hl)
  984.         ld ly,a
  985.         inc l
  986.         ld a,(hl)
  987.         ld hy,a
  988.         call setpgsscr40008000
  989.         ld c,e ;y
  990.         ld a,d ;x
  991.         srl a
  992.         add a,sprmaxwid-1
  993.         ld e,a
  994. ;e=x = -(sprmaxwid-1)..159 (ъюфшЁєхЄё  ъръ x+(sprmaxwid-1))
  995. ;c=y = -(sprmaxhgt-1)..199 (ъюфшЁєхЄё  ъръ хёЄ№)
  996.         call prspr
  997.         pop iy
  998.         call setpgcodec000
  999.         call setpgsmain40008000
  1000.         pop de
  1001.         pop bc
  1002.         ret
  1003.        endif
  1004.  
  1005.         include "prspr.asm"
  1006.  
  1007.         if EGA
  1008. gettilebuf
  1009.        ds 128
  1010.         endif
  1011.        if EGA
  1012. GetTileToHL_DEXY
  1013. ;hl=addr
  1014. ;e=Y
  1015. ;d=X
  1016.         push bc
  1017.         push de
  1018.         sla d
  1019.         sla d
  1020.         sla d
  1021.         sla e
  1022.         sla e
  1023.         sla e        
  1024.         ld bc,0x1008 ;b=hgt,c=wid (/2)
  1025.         jr GetBuf2CxB_DExy_ToHL
  1026.        if 1==0
  1027.        ld b,12*8
  1028. gettilefake0
  1029.        ld a,r
  1030.        ld (hl),a
  1031.        inc hl
  1032.        djnz gettilefake0
  1033.        pop de
  1034.        pop bc
  1035.        ret
  1036.        endif
  1037. GetBuf24x16_DExy
  1038. ;e=y
  1039. ;d=x
  1040.         push bc
  1041.         push de
  1042.         ld bc,0x100c ;b=hgt,c=wid (/2)
  1043.         ld hl,rebuf24x16
  1044. GetBuf2CxB_DExy_ToHL
  1045.         push hl ;gfx
  1046.         ld a,d ;x
  1047.         srl a
  1048.         srl a
  1049.         srl a
  1050.          add a,4
  1051.         ld l,e ;y
  1052.         ld h,0
  1053.         ld d,h
  1054.         ld e,l
  1055.         add hl,hl
  1056.         add hl,hl
  1057.         add hl,de ;*5
  1058.          add hl,hl
  1059.          add hl,hl
  1060.          add hl,hl ;*40
  1061.         add a,l
  1062.         ld l,a
  1063.         ld a,h
  1064.         adc a,0x40
  1065.         ld h,a
  1066.         pop de ;gfx
  1067. ;de=gfx
  1068. ;hl=scr
  1069.         push bc
  1070.         call setpgsscr40008000
  1071.         pop bc
  1072. getimgega0
  1073.         push bc
  1074.         ld hx,b
  1075.         push hl
  1076.         ld bc,40
  1077. getimgegacolumn0
  1078.         ld a,(hl)
  1079.         ld (de),a
  1080.         inc de
  1081.         add hl,bc
  1082.         dec hx
  1083.         jr nz,getimgegacolumn0
  1084.         pop hl
  1085.         ld a,0x9f;0xa0
  1086.         cp h
  1087.         ld bc,0x4000
  1088.         adc hl,bc
  1089.         jp pe,getimgegacolumn0q ;т яюыютшэх ёыєўрхт
  1090. ;8000->ё000 (эрфю 6000) шыш a000->e001 (эрфю 4001)
  1091.          inc a
  1092.         xor h
  1093.         ld h,a
  1094. getimgegacolumn0q
  1095.         pop bc
  1096.         dec c
  1097.         jr nz,getimgega0
  1098.         call setpgsmain40008000
  1099.         pop de
  1100.         pop bc
  1101.         ret
  1102.  
  1103. ReBuf24x16_DExy
  1104. ;e=y
  1105. ;d=x (width 16 if multiple of 8)
  1106.         push bc
  1107.         push de
  1108.         ld bc,0x1008 ;b=hgt,c=wid (/2)
  1109.         ld a,d
  1110.         and 7
  1111.         jr z,$+4
  1112.          ld c,0x0c
  1113.         ld a,d ;x
  1114.         srl a
  1115.         srl a
  1116.         srl a
  1117.          add a,4
  1118.         ld l,e ;y
  1119.         ld h,0
  1120.         ld d,h
  1121.         ld e,l
  1122.         add hl,hl
  1123.         add hl,hl
  1124.         add hl,de ;*5
  1125.          add hl,hl
  1126.          add hl,hl
  1127.          add hl,hl ;*40
  1128.         add a,l
  1129.         ld l,a
  1130.         ld a,h
  1131.         adc a,0x40
  1132.         ld h,a
  1133.         ld de,rebuf24x16
  1134. ;de=gfx
  1135. ;hl=scr
  1136.         call primgega
  1137.         pop de
  1138.         pop bc
  1139.         ret
  1140.  
  1141. buf24x16
  1142.         ds 12*16
  1143. buf24x16_2
  1144.         ds 12*16
  1145. gettilebuf2
  1146.         ds 8*16
  1147. rebuf24x16
  1148.         ds 12*16
  1149.        endif
  1150.  
  1151.        if EGA
  1152. DrawSprite16x16_HL_DExy
  1153. ;hl=gfx
  1154. ;e=y
  1155. ;d=x (pixel perfect!)
  1156.         push bc
  1157.         push de
  1158.         ex de,hl
  1159.         ld b,0
  1160.         ld a,h ;x
  1161.         srl a
  1162.         ;ld l,l ;y
  1163.         ld c,l
  1164.         srl a ;x bit 0
  1165.         ;ld h,0x40/32/2
  1166.         ;jr nc,$+4 ;x bit 0
  1167.         ; ld h,0x80/32/2
  1168.          ld h,b;0
  1169.          rl h
  1170.          inc h ;0x40/32/2 шыш 0x80/32/2
  1171.         srl a ;x bit 1
  1172.          rl h
  1173.         add hl,hl
  1174.         add hl,hl
  1175.         add hl,bc
  1176.         add hl,hl
  1177.         add hl,hl
  1178.         add hl,hl ;y*40+scrbase
  1179.          if scrbase&0xff
  1180.          add a,scrbase&0xff
  1181.          endif
  1182. ;a=x/4
  1183.         add a,l
  1184.         ld l,a
  1185.         adc a,h
  1186.         sub l
  1187.         ld h,a ;hl=scr
  1188. ;de=gfx
  1189. ;hl=scr
  1190.         ld bc,0x1008 ;b=hgt,c=wid (/2)
  1191.         call primgega
  1192.         pop de
  1193.         pop bc
  1194.         ret
  1195.        endif
  1196.  
  1197.        if EGA
  1198. ClearTile_DExy
  1199.         ;ret
  1200. ;E=y
  1201. ;D=x (width 24 if not multiple of 8)
  1202.         push bc
  1203.         push de
  1204.         ld bc,0x1008 ;b=hgt,c=wid (/2)
  1205.         ld a,d ;x
  1206.         and 7
  1207.         jr z,$+4
  1208.          ld c,0x0c ;wid (/2)
  1209.         ld a,d
  1210.         srl a
  1211.         srl a
  1212.         srl a
  1213.          add a,4
  1214.         ld l,e ;y
  1215.         ld h,0
  1216.         ld d,h
  1217.         ld e,l
  1218.         add hl,hl
  1219.         add hl,hl
  1220.         add hl,de ;*5
  1221.          add hl,hl
  1222.          add hl,hl
  1223.          add hl,hl ;*40
  1224.         add a,l
  1225.         ld l,a
  1226.         ld a,h
  1227.         adc a,0x40
  1228.         ld h,a
  1229.         ld de,zeros24x16
  1230. ;de=gfx
  1231. ;hl=scr
  1232.         call primgega
  1233.         pop de
  1234.         pop bc
  1235.         ret
  1236. zeros24x16
  1237.         ds 12*16
  1238.        endif
  1239.  
  1240. readbmphead_pal
  1241.         ld de,bgpush_bmpbuf
  1242.         ld hl,14+2;54+(4*16)
  1243. ;de=buf
  1244. ;hl=size
  1245.         call readstream_file
  1246.         ld de,bgpush_bmpbuf
  1247.         ld hl,(bgpush_bmpbuf+14)
  1248.         dec hl
  1249.         dec hl
  1250. ;de=buf
  1251. ;hl=size
  1252.         call readstream_file
  1253.         ld de,bgpush_bmpbuf
  1254.         ld hl,+(4*16)
  1255. ;de=buf
  1256. ;hl=size
  1257.         call readstream_file
  1258.  
  1259.         ld hl,bgpush_bmpbuf;+54
  1260.         ld ix,pal
  1261.         ld b,16
  1262. recodepal0
  1263.         ld e,(hl)
  1264.         inc hl
  1265.         ld d,(hl)
  1266.         inc hl
  1267.         push hl
  1268.         ld l,(hl) ;e=B, d=G, l=R
  1269.         call readfile_rgbtopal
  1270.         pop hl
  1271.         inc hl
  1272.         inc hl
  1273.         djnz recodepal0
  1274.         ret
  1275.  
  1276.         macro RECOLOR
  1277.         ld a,(de)
  1278.         inc de
  1279.         ld ($+4),a
  1280.         ld a,(trecolor)
  1281.         ld (hl),a
  1282.         endm
  1283. readbmpscr
  1284.         ld hl,0x4000+(199*40)
  1285.         ld b,200
  1286. readbmpscr0
  1287.         push bc
  1288.         push hl
  1289.         ld de,bgpush_bmpbuf
  1290.         ld hl,320/2
  1291. ;de=buf
  1292. ;hl=size
  1293.         push de
  1294.         call readstream_file
  1295.         pop de
  1296.         pop hl
  1297.         push hl
  1298.         ld b,40
  1299. readbmpscr00        
  1300.         RECOLOR
  1301.         ld a,h
  1302.         add a,0x40
  1303.         ld h,a
  1304.         RECOLOR
  1305.         ld a,h
  1306.         add a,0x20-0x40
  1307.         ld h,a
  1308.         RECOLOR
  1309.         ld a,h
  1310.         add a,0x40
  1311.         ld h,a
  1312.         RECOLOR
  1313.         ld a,h
  1314.         sub 0x60
  1315.         ld h,a
  1316.         inc hl
  1317.         djnz readbmpscr00
  1318.         pop hl
  1319.         ld bc,-40
  1320.         add hl,bc
  1321.         pop bc
  1322.         djnz readbmpscr0
  1323.         ret
  1324.  
  1325. readfile_rgbtopal
  1326. ;e=B, d=G, l=R
  1327.         call calcRGBtopal_pp
  1328.         ld (ix+1),a
  1329.         call calcRGBtopal_pp
  1330.         ld (ix),a
  1331.         inc ix
  1332.         inc ix
  1333.         ret
  1334.  
  1335. calcRGBtopal_pp
  1336. ;e=B, d=G, l=R
  1337. ;DDp palette: %grbG11RB(low),%grbG11RB(high), ??oN????N
  1338.         xor a
  1339.         rl e  ;B
  1340.         rra
  1341.         rl l  ;R
  1342.         rra
  1343.         rrca
  1344.         rrca
  1345.         rl d  ;G
  1346.         rra
  1347.         rl e  ;b
  1348.         rra
  1349.         rl l  ;r
  1350.         rra
  1351.         rl d  ;g
  1352.         rra
  1353.         cpl
  1354.         ret
  1355.  
  1356. ;------------------
  1357. ; Keyboard scanning
  1358. ;------------------
  1359. ; from keyboard and s-inkey$
  1360. ; returns 1 or 2 keys in DE, most significant shift first if any
  1361. ; key values 0-39 else 255
  1362.  
  1363. ;; KEY-SCAN
  1364. L028E   LD      L,$2F           ; initial key value
  1365.                                 ; valid values are obtained by subtracting
  1366.                                 ; eight five times.
  1367.         LD      DE,$FFFF        ; a buffer for 2 keys.
  1368.  
  1369.         LD      BC,$FEFE        ; the commencing port address
  1370.                                 ; B holds 11111110 initially and is also
  1371.                                 ; used to count the 8 half-rows
  1372. ;; KEY-LINE
  1373. L0296   IN      A,(C)           ; read the port to A - bits will be reset
  1374.                                 ; if a key is pressed else set.
  1375.         CPL                     ; complement - pressed key-bits are now set
  1376.         AND     $1F             ; apply 00011111 mask to pick up the
  1377.                                 ; relevant set bits.
  1378.  
  1379.         JR      Z,L02AB         ; forward to KEY-DONE if zero and therefore
  1380.                                 ; no keys pressed in row at all.
  1381.  
  1382.         LD      H,A             ; transfer row bits to H
  1383.         LD      A,L             ; load the initial key value to A
  1384.  
  1385. ;; KEY-3KEYS
  1386. L029F   INC     D               ; now test the key buffer
  1387.         RET     NZ              ; if we have collected 2 keys already
  1388.                                 ; then too many so quit.
  1389.  
  1390. ;; KEY-BITS
  1391. L02A1   SUB     $08             ; subtract 8 from the key value
  1392.                                 ; cycling through key values (top = $27)
  1393.                                 ; e.g. 2F>   27>1F>17>0F>07
  1394.                                 ;      2E>   26>1E>16>0E>06
  1395.         SRL     H               ; shift key bits right into carry.
  1396.         JR      NC,L02A1        ; back to KEY-BITS if not pressed
  1397.                                 ; but if pressed we have a value (0-39d)
  1398.  
  1399.         LD      D,E             ; transfer a possible previous key to D
  1400.         LD      E,A             ; transfer the new key to E
  1401.         JR      NZ,L029F        ; back to KEY-3KEYS if there were more
  1402.                                 ; set bits - H was not yet zero.
  1403.  
  1404. ;; KEY-DONE
  1405. L02AB   DEC     L               ; cycles 2F>2E>2D>2C>2B>2A>29>28 for
  1406.                                 ; each half-row.
  1407.         RLC     B               ; form next port address e.g. FEFE > FDFE
  1408.         JR      C,L0296         ; back to KEY-LINE if still more rows to do.
  1409.  
  1410.         LD      A,D             ; now test if D is still FF ?
  1411.         INC     A               ; if it is zero we have at most 1 key
  1412.                                 ; range now $01-$28  (1-40d)
  1413.         RET     Z               ; return if one key or no key.
  1414.  
  1415.         CP      $28             ; is it capsshift (was $27) ?
  1416.         RET     Z               ; return if so.
  1417.  
  1418.         CP      $19             ; is it symbol shift (was $18) ?
  1419.         RET     Z               ; return also
  1420.  
  1421.         LD      A,E             ; now test E
  1422.         LD      E,D             ; but first switch
  1423.         LD      D,A             ; the two keys.
  1424.         CP      $18             ; is it symbol shift ?
  1425.         RET                     ; return (with zero set if it was).
  1426.                                 ; but with symbol shift now in D
  1427.  
  1428.  
  1429.         align 256
  1430. trecolor
  1431. ;%00003210 => %.3...210
  1432.         dup 256
  1433. _3=$&8
  1434. _210=$&7
  1435. _3L=($>>4)&8
  1436. _210L=($>>4)&7
  1437.         db (_3L*0x08) + (_210L*0x01) + (_3*0x10) + (_210*0x08)
  1438.         edup
  1439.  
  1440. bgpush_bmpbuf
  1441.         ds 320
  1442.  
  1443. res_path
  1444.         db "midnight",0
  1445. ;bmpfilename
  1446.         ;db "solkey.bmp",0
  1447. muzfilename
  1448.         db "music.o",0
  1449. levelfilenames
  1450.         db 1
  1451.         dw 0xc000
  1452.         db "level2.o",0
  1453.         db 1
  1454.         dw 0xe000
  1455.         db "level1.o",0
  1456.         db 3
  1457.         dw 0xc000
  1458.         db "level3.o",0
  1459.         db 3
  1460.         dw 0xe000
  1461.         db "level4.o",0
  1462.         db 4
  1463.         dw 0xc000
  1464.         db "level5.o",0
  1465.         db 4
  1466.         dw 0xe000
  1467.         db "level6.o",0
  1468.         db 6
  1469.         dw 0xc000
  1470.         db "level7.o",0
  1471.         db 6
  1472.         dw 0xe000
  1473.         db "level8.o",0
  1474.         db 7
  1475.         dw 0xc000
  1476.         db "level9.o",0
  1477.         db -1
  1478.  
  1479.         include "../../_sdk/file.asm"
  1480.  
  1481.         ds 0x3d00-$
  1482.         incbin "font88"
  1483.         ds 0x4000-$
  1484.         incbin "midnight.scr"
  1485.         ;incbin "slabage/sprdata.bin"
  1486. ;tilegfx=$+0x8000
  1487.         ;incbin "slabage/tiles.bin"
  1488. ;panelgfx=$+0x8000
  1489.         ;incbin "slabage/panel.bin"
  1490.  
  1491.         ds MENUSTART-$
  1492.         include "Mirror.a80"
  1493.  
  1494.         ds CODE-$;0x5b00-$
  1495.         include "Game.a80"
  1496.  
  1497.         org LEVELDATA
  1498.         ;ds LEVELDATA-$
  1499. level1
  1500.         include "Level_01.a80"
  1501. level1_sz=$-level1
  1502.         include "Page1_FF00.a80"
  1503.  
  1504.         ds MIRPAGE-$
  1505. ;****************************************************************************
  1506. ;** MIRROR PAGE                                                            **
  1507. ;****************************************************************************
  1508.  
  1509.                 IF MUSICALSO=0
  1510.  
  1511.                 ;ORG MIRPAGE
  1512.  
  1513.                 DB #00,#80,#40,#C0,#20,#A0,#60,#E0,#10,#90,#50,#D0,#30,#B0,#70,#F0
  1514.                 DB #08,#88,#48,#C8,#28,#A8,#68,#E8,#18,#98,#58,#D8,#38,#B8,#78,#F8
  1515.                 DB #04,#84,#44,#C4,#24,#A4,#64,#E4,#14,#94,#54,#D4,#34,#B4,#74,#F4
  1516.                 DB #0C,#8C,#4C,#CC,#2C,#AC,#6C,#EC,#1C,#9C,#5C,#DC,#3C,#BC,#7C,#FC
  1517.                 DB #02,#82,#42,#C2,#22,#A2,#62,#E2,#12,#92,#52,#D2,#32,#B2,#72,#F2
  1518.                 DB #0A,#8A,#4A,#CA,#2A,#AA,#6A,#EA,#1A,#9A,#5A,#DA,#3A,#BA,#7A,#FA
  1519.                 DB #06,#86,#46,#C6,#26,#A6,#66,#E6,#16,#96,#56,#D6,#36,#B6,#76,#F6
  1520.                 DB #0E,#8E,#4E,#CE,#2E,#AE,#6E,#EE,#1E,#9E,#5E,#DE,#3E,#BE,#7E,#FE
  1521.                 DB #01,#81,#41,#C1,#21,#A1,#61,#E1,#11,#91,#51,#D1,#31,#B1,#71,#F1
  1522.                 DB #09,#89,#49,#C9,#29,#A9,#69,#E9,#19,#99,#59,#D9,#39,#B9,#79,#F9
  1523.                 DB #05,#85,#45,#C5,#25,#A5,#65,#E5,#15,#95,#55,#D5,#35,#B5,#75,#F5
  1524.                 DB #0D,#8D,#4D,#CD,#2D,#AD,#6D,#ED,#1D,#9D,#5D,#DD,#3D,#BD,#7D,#FD
  1525.                 DB #03,#83,#43,#C3,#23,#A3,#63,#E3,#13,#93,#53,#D3,#33,#B3,#73,#F3
  1526.                 DB #0B,#8B,#4B,#CB,#2B,#AB,#6B,#EB,#1B,#9B,#5B,#DB,#3B,#BB,#7B,#FB
  1527.                 DB #07,#87,#47,#C7,#27,#A7,#67,#E7,#17,#97,#57,#D7,#37,#B7,#77,#F7
  1528.                 DB #0F,#8F,#4F,#CF,#2F,#AF,#6F,#EF,#1F,#9F,#5F,#DF,#3F,#BF,#7F,#FF
  1529.                
  1530.                 ENDIF
  1531.  
  1532. ;***************************************
  1533. ;** PAGE 0 DATA                       **
  1534. ;***************************************
  1535.  
  1536.                 ;ORG PAGE0
  1537.                 ds PAGE0-$
  1538.  
  1539. YBOUNCE         DB #FF,#00,#01,#00
  1540.  
  1541. INFLIVES        DB INFLIF
  1542. INFAMMO         DB INFAMM
  1543. WEPSELECT       DB WEPSEL
  1544. SPACEBARCHEAT   DB SPACETOKILL
  1545.  
  1546. SCORETEXT       DB PRAT,21,20,PRSIZE
  1547.                 INC D:NOP
  1548.                 DB PRINK,$45,PRINK2,$47
  1549. SCORE           DB "00000000",PRSIZE,0,PREOF
  1550.  
  1551. PD              EQU 8
  1552. XADDS           DB 0+00,0+PD,0+PD,0+PD,0+00,0-PD,0-PD,0-PD
  1553. YADDS           DB 0-PD,0-PD,0+00,0+PD,0+PD,0+PD,0+00,0-PD
  1554.  
  1555. V               EQU 4
  1556. W               EQU V*2
  1557. XADS            DB 00,+V,+W,+W,+W,+W,+W,+V,00,-V,-W,-W,-W,-W,-W,-V
  1558. YADS            DB -W,-W,-W,-V,00,+V,+W,+W,+W,+W,+W,+V,00,-V,-W,-W
  1559.  
  1560. JADDS           DB #00,#08,#00,#00,#00,#00,#00,#00
  1561.                 DB #F8,#00,#08,#00,#08,#00,#08,#00
  1562.  
  1563. DAMAGETAB       DB 01,01,03,02,00,06,03,03
  1564.                 DB 01,02,06,04,00,06,03,03
  1565.                 DB 02,01
  1566.  
  1567. NORET           EQU 0
  1568. LOSELIFE        EQU 1
  1569. NXTLEV          EQU 2
  1570. ;BREAK           EQU 3
  1571.  
  1572. RETMODE         DB NORET
  1573.  
  1574. RETMODES        DW GAMEOVER
  1575.                 DW NEXTLEVEL
  1576. ;                DW TESTLOADLEV1
  1577.  
  1578. BADDAT          DS NOBAD*BADLEN,0
  1579.  
  1580. FLAMEDIR        DS NOFLAMES,2
  1581. FLAMEXYS        DS NOFLAMES*2,0
  1582.  
  1583. PAGEEND
  1584.  
  1585. end
  1586.         ;page 0
  1587.         savebin "midnight.com",begin,end-begin
  1588.         savebin "midnight/level1.o",level1,level1_sz
  1589.  
  1590.         slot 3
  1591.         page 1
  1592.         org #C000
  1593. level2
  1594.         include "Level_02.a80"
  1595. level2_sz=$-level2
  1596.         ;org #E000
  1597.         ;include "Level_01.a80"
  1598.  
  1599.         page 3
  1600.         org #C000
  1601. level3
  1602.         include "Level_03.a80"
  1603. level3_sz=$-level3
  1604.         org #E000
  1605. level4
  1606.         include "Level_04.a80"
  1607. level4_sz=$-level4
  1608.  
  1609.         page 4
  1610.         org #C000
  1611. level5
  1612.         include "Level_05.a80"
  1613. level5_sz=$-level5
  1614.         org #E000
  1615. level6
  1616.         include "Level_06.a80"
  1617. level6_sz=$-level6
  1618.  
  1619.         page 6
  1620.         org #C000
  1621. level7
  1622.         include "Level_07.a80"
  1623. level7_sz=$-level7
  1624.         org #E000
  1625. level8
  1626.         include "Level_08.a80"
  1627. level8_sz=$-level8
  1628.  
  1629.         page 7
  1630.         org #C000
  1631. level9
  1632.         include "Level_09.a80"
  1633. level9_sz=$-level9
  1634.         org #E000
  1635. music
  1636.         include "Music.a80"
  1637. music_sz=$-music
  1638.  
  1639.         display "End=",end
  1640.         ;display "Free after end=",/d,#c000-end
  1641.         display "Size ",/d,end-begin," bytes"
  1642.         page 1
  1643.         savebin "midnight/level2.o",level2,level2_sz
  1644.         page 3
  1645.         savebin "midnight/level3.o",level3,level3_sz
  1646.         savebin "midnight/level4.o",level4,level4_sz
  1647.         page 4
  1648.         savebin "midnight/level5.o",level5,level5_sz
  1649.         savebin "midnight/level6.o",level6,level6_sz
  1650.         page 6
  1651.         savebin "midnight/level7.o",level7,level7_sz
  1652.         savebin "midnight/level8.o",level8,level8_sz
  1653.         page 7
  1654.         savebin "midnight/level9.o",level9,level9_sz
  1655.         savebin "midnight/music.o",music,music_sz
  1656.         LABELSLIST "../../../us/user.l"
  1657.