Subversion Repositories NedoOS

Rev

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