?login_element?

Subversion Repositories NedoOS

Rev

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

  1.         DEVICE ZXSPECTRUM128
  2.         include "../../_sdk/sys_h.asm"
  3. ;0x0100..0x3eff - subroutines
  4. ;0x3f00..0x3fff - stack
  5. ;0x4000..0x7fff - VRAM
  6. ;0x8000..0xbfff - game/paged for screen
  7. ;0xc000..0xffff - scratchpad RAM/paged for screen
  8.  
  9. INTSTACK=0x0100;0x3f00
  10. VDPSTACK=INTSTACK-64
  11. STACK=0x4000;=INTSTACK-64
  12.  
  13. SPRITESON=1;0
  14.  
  15.         org PROGSTART
  16. begin
  17.         ld sp,STACK
  18.         OS_HIDEFROMPARENT
  19.  
  20.         ld e,0+128 ;EGA +keep
  21.         OS_SETGFX ;e=0:EGA, e=2:MC, e=3:6912, e=6:text ;+SET FOCUS ;e=-1: disable gfx (out: e=old gfxmode)
  22.  
  23.         ld e,0
  24.         OS_SETSCREEN
  25.         ld e,0 ;color byte
  26.         OS_CLS
  27.         ld e,1
  28.         OS_SETSCREEN
  29.         ld e,0 ;color byte
  30.         OS_CLS
  31.  
  32.         OS_GETMAINPAGES
  33. ;dehl=pages in 0000,4000,8000,c000
  34.         ld a,e
  35.         ld (pgcode4000),a
  36.         ld a,h
  37.         ld (pgcode8000),a
  38.         ld a,l
  39.         ld (pgcodec000),a
  40.  
  41.         OS_NEWPAGE
  42.         ld a,e
  43.         ld (pgtiles),a
  44.  
  45.         ld de,pal
  46.         OS_SETPAL
  47.  
  48.         call swapimer
  49.  
  50.         jp GO
  51.  
  52. pal
  53. ;DDp palette: %grbG11RB(low),%grbG11RB(high), inverted
  54.                    ;bg=1  ;зел  ;салат  ;син  ;небо  ;крас  ;ярко-голуб
  55.         dw 0xffff,0xfefe,0xcfcf,0x4f4f,0xdede,0xcccc,0xfdfd,0xcece
  56.         dw 0xbdbd,0xacac,0x2d2d,0x2c2c,0xefef,0x4e4e,0xecec,0x0c0c
  57.            ;флаг  ;роз   ;древко ;лим  ;тзел  ;???    ;road
  58. ;oldtimer
  59. ;        dw 0
  60. quiter
  61.         halt
  62.         ;ld a,(pgmuznum)
  63.         ;SETPG32KHIGH
  64.         ;call muz
  65.         call shutay
  66.         call swapimer
  67.         QUIT
  68.  
  69.  
  70. swapimer
  71.         di
  72.         ld de,0x0038
  73.         ld hl,oldimer
  74.         ld bc,3
  75. swapimer0
  76.         ld a,(de)
  77.         ldi ;[oldimer] -> [0x0038]
  78.         dec hl
  79.         ld (hl),a ;[0x0038] -> [oldimer]
  80.         inc hl
  81.         jp pe,swapimer0
  82.         ei
  83.         ret
  84. oldimer
  85.         jp on_int ;заменится на код из 0x0038
  86.         jp 0x0038+3
  87.  
  88. on_int
  89. ;restore stack with de
  90.         ld (on_int_hl),hl
  91.         ld (on_int_sp),sp
  92.         pop hl
  93.         ld (on_int_sp2),sp
  94.         ld (on_int_jp),hl
  95.        
  96.         ld sp,INTSTACK
  97.        
  98.         push af
  99.         push bc
  100.         push de
  101.        
  102. ;imer_curscreen_value=$+1
  103.          ;ld a,0
  104.          ;ld bc,0x7ffd
  105.          ;out (c),a
  106.  
  107.         ex de,hl;ld hl,0
  108. on_int_sp=$+1
  109.         ld (0),hl ;восстановили запоротый стек
  110.        
  111.         push ix
  112.         push iy
  113.         ex af,af' ;'
  114.         exx
  115.         push af
  116.         push bc
  117.         push de
  118.         push hl
  119. ;curpalette=$+1
  120.         ;ld de,wolfpal
  121.         ;OS_SETPAL
  122.  
  123. curscrnum_int=$+1
  124.         ld e,0
  125.         OS_SETSCREEN
  126.        
  127. ;pgmuznum=$+1
  128. ;        ld a,0
  129. ;        SETPG32KHIGH
  130.        
  131.          call oldimer
  132.        
  133.         GET_KEY
  134.         ld (curkey),a
  135.  
  136.         ld a,(curpg32klow) ;ok
  137.         push af
  138.         ld a,(curpg32khigh) ;ok
  139.         push af
  140.         call setpgcode8000c000
  141.         call MUZHOOK ;muzplay
  142.         pop af
  143.         SETPG32KHIGH
  144.         pop af
  145.         SETPG32KLOW
  146. ;pgc000=$+1
  147. ;        ld a,0
  148. ;        SETPG32KHIGH
  149.        
  150.         pop hl
  151.         pop de
  152.         pop bc
  153.         pop af
  154.         exx
  155.         ex af,af' ;'
  156.         pop iy
  157.         pop ix
  158.        
  159.         ;ld hl,(timer)
  160.         ;inc hl
  161.         ;ld (timer),hl
  162.  
  163.         pop de
  164.         pop bc
  165.         pop af
  166.        
  167. on_int_hl=$+1
  168.         ld hl,0
  169. on_int_sp2=$+1
  170.         ld sp,0
  171.         ei
  172. on_int_jp=$+1
  173.         jp 0
  174.  
  175. setpgtiles4000
  176. pgtiles=$+1
  177.         ld a,0
  178.         SETPG16K
  179.         ret
  180.  
  181. setpgtiles8000
  182.         ld a,(pgtiles)
  183.         SETPG32KLOW
  184.         ret
  185.  
  186. setpgcode4000
  187. pgcode4000=$+1
  188.         ld a,0
  189.         SETPG16K
  190.         ret
  191.  
  192. setpgcode8000c000
  193. pgcode8000=$+1
  194.         ld a,0
  195.         SETPG32KLOW
  196. pgcodec000=$+1
  197.         ld a,0
  198.         SETPG32KHIGH
  199.         ret
  200.  
  201. MUZHOOK;#FD9F ;$FD9F is one of the interrupt service routine hooks (HTIMI) and it's called every 50/60 times per second by the BIOS.
  202.         ret
  203.         ret
  204.         ret
  205.  
  206. gentiles
  207.         ;jr $
  208.         pop hl
  209.         ld (gentilesjp),hl
  210.         ld (gentilessp),sp
  211.         ld sp,VDPSTACK
  212.         ;call setpgtiles4000
  213.  
  214.         ld hl,wasfont
  215.         ld de,0x4100
  216.         ld bc,8*('Z'+1-' ')
  217.         ldir
  218.  
  219.         ld l,0
  220. gentiles0
  221.         ld h,0x20
  222.         ld d,0x40/8
  223.         ld a,l
  224.         add a,a
  225.         rl d
  226.         add a,a
  227.         rl d
  228.         add a,a
  229.         rl d
  230.         ld e,a
  231.         dup 8
  232.         ld a,(de)
  233.          ld (hl),-1;0
  234.          rla
  235.          rr (hl)
  236.          rla
  237.          rr (hl)
  238.         set 3,h
  239.          ld (hl),-1;0
  240.          rla
  241.          rr (hl)
  242.          rla
  243.          rr (hl)
  244.         res 3,h
  245.         set 4,h
  246.          ld (hl),-1;0
  247.          rla
  248.          rr (hl)
  249.          rla
  250.          rr (hl)
  251.         set 3,h
  252.          ld (hl),-1;0
  253.          rla
  254.          rr (hl)
  255.          rla
  256.          rr (hl)        
  257.         res 3,h
  258.         res 4,h
  259.         inc e
  260.         inc h
  261.         edup
  262.        
  263.         ld h,0x20
  264. gentiles0atr0
  265.         ld d,0x60/8
  266.         ld a,l
  267.         add a,a
  268.         rl d
  269.         add a,a
  270.         rl d
  271.         add a,a
  272.         rl d
  273.         xor h
  274.         and 0xf8
  275.         xor h
  276.         ld e,a
  277.         ld a,(de) ;IiiiPppp
  278.         rra
  279.         rra
  280.         rra
  281.         rra
  282.         call geninkbyte
  283.         ld c,a
  284.         ld a,(de)
  285.         call geninkbyte
  286.         ld b,a
  287.         ;ld bc,0b0000000011111111
  288. ;c=ink (IIiiiiii)
  289. ;b=paper (PPpppppp)
  290.         ld a,(hl)
  291.         rla
  292.         sbc a,a
  293.         ld e,a ;RRRRRRRR
  294.         ld a,(hl)
  295.         rla
  296.         rla
  297.         sbc a,a ;LLLLLLLL
  298.         xor e
  299.         and 0b01000111
  300.         xor e
  301.         ld d,a
  302. ;a=%RLRRRLLL        
  303.         and c ;ink (IIiiiiii)
  304.         ld e,a
  305.         ld a,d
  306.         cpl
  307.         and b ;paper (PPpppppp)
  308.         or e
  309.         ld (hl),a
  310.         inc h
  311.         bit 6,h
  312.         jr z,gentiles0atr0
  313.        
  314.         inc l
  315.         jp nz,gentiles0
  316.  
  317.         ;call setpgcode4000
  318. ;gen sprites
  319. ;The Sprite Pattern Table occupies 2 KB of VRAM from 3800H to 3FFFH. It contains two hundred and fifty-six 8x8 pixel patterns, numbered from 0 to 255.
  320. ;AC
  321. ;BD
  322. ;8 bytes block A
  323. ;8 bytes block B
  324. ;8 bytes block C
  325. ;8 bytes block D
  326. ;pattern 0..3 = pattern 0, pattern 4..7 = pattern 1...
  327. ;(decoded to 128 bytes per pattern in pgtiles)
  328.         call setpgtiles8000
  329.  
  330.         ld hl,0x4000+0x3800;0x1800
  331.         ld de,0x8000
  332.  
  333.         ld b,2*64 ;halfsprites
  334. genspr0
  335.         push bc
  336.         ld c,4
  337. genspr0subcolumns
  338.         push hl
  339.         ld b,16
  340. genspr00
  341.         xor a ;ld a,0xff
  342.         rlc (hl)
  343.         jr nc,$+4
  344.         xor 0b01000111 ;don't keep left pixel
  345.         rlc (hl)
  346.         jr nc,$+4
  347.         xor 0b10111000 ;don't keep right pixel
  348.         ld (de),a
  349.         inc hl
  350.         inc de
  351.         djnz genspr00
  352.         pop hl
  353.         dec c
  354.         jr nz,genspr0subcolumns
  355.         ld bc,16
  356.         add hl,bc ;next column (halfsprite)
  357.         pop bc
  358.         djnz genspr0
  359.        
  360.         call setpgcode8000c000
  361. gentilessp=$+1
  362.         ld sp,0
  363. gentilesjp=$+1
  364.         jp 0
  365.  
  366. geninkbyte
  367. ;a=????Iiii
  368. ;out: a=IIiiiiii
  369.         ld b,a
  370.         rla
  371.         rla
  372.         rla
  373.         xor b
  374.         and 0b01111000
  375.         xor b ;?Iiiiiii
  376.         rla   ;Iiiiiii?
  377.         rlca  ;iiiiii?I
  378.         rra   ;Iiiiiii? (CY=I)
  379.         rra
  380.         ret
  381.  
  382.         MACRO SPRCOLUMN
  383.        dup 15
  384.         ld a,(de)
  385.         xor (hl) ;and (hl)
  386.         ld (hl),a;0xaa
  387.         inc e
  388.         add hl,bc ;40
  389.        edup
  390.         ld a,(de)
  391.         xor (hl) ;and (hl)
  392.         ld (hl),a;0xaa
  393.         inc e
  394.         endm
  395.  
  396.         macro NEXTCOLUMN
  397.         bit 6,h
  398.         set 6,h
  399.         jr z,$+2+4+2+2+1
  400.         ld a,h
  401.         xor 0x60
  402.         ld h,a
  403.         and 0x20
  404.         jr nz,$+3
  405.         inc hl
  406.         endm
  407.  
  408. ;The Name Table occupies 768 bytes of VRAM from 1800H to 1AFFH (!!!3800!!!), the same as in 32x24 Text Mode. The table is initialized with the character code sequence 0 to 255 repeated three times and is then left untouched, in this mode it is the Character Pattern Table which is modified during normal operation.
  409.  
  410. ;The Character Pattern Table occupies 6 KB of VRAM from 0000H to 17FFH. While its structure is the same as in the text modes it does not contain a character set but is initialized to all 0 pixels. The first 2 KB of the Character Pattern Table is addressed by the character codes from the first third of the Name Table, the second 2 KB by the central third of the Name Table and the last 2 KB by the final third of the Name Table. Because of the sequential pattern in the Name Table the entire Character Pattern Table is read out linearly during a video frame.
  411.  
  412. emulVDP
  413.         pop hl
  414.         ld (emulVDPjp),hl
  415.         ld (emulVDPsp),sp
  416.         ld sp,VDPSTACK
  417.  
  418.         push bc
  419.         push de
  420.         push hl
  421. curkey=$+1
  422.         ld a,0
  423.         cp key_esc
  424.         jp z,quiter
  425.         ;ld a,(user_scr0_low) ;ok
  426.         ;SETPG32KLOW
  427.         ;ld a,(user_scr0_high) ;ok
  428.         ;SETPG32KHIGH
  429.         call setpgsscr8000c000
  430. ;TODO draw only changed tiles
  431.         ld de,0x4000+0x1800 ;tilemap
  432.         ld hl,0x8000+4 ;screen
  433.         ;ld hx,0x40 ;tile gfx base
  434.         ld b,24
  435. emulVDPtiles0
  436.         push bc
  437.         ld a,24
  438.         sub b
  439.         rra
  440.         rra
  441.         rra
  442.         and 3
  443.         add a,0x40/8
  444.         ld hx,a ;tile gfx base
  445.         push hl
  446.         ld b,32
  447. emulVDPtiles1
  448.         ld a,(de) ;tile
  449.         push bc
  450.         push de
  451.         push hl
  452.        
  453.         ld bc,40
  454.        
  455.         ld e,a
  456.        
  457.         push hl
  458.        
  459.         ld d,0x20
  460.         push hl
  461.         dup 7
  462.         ld a,(de)
  463.         ld (hl),a
  464.         inc d
  465.         add hl,bc
  466.         edup
  467.         ld a,(de)
  468.         ld (hl),a
  469.         pop hl
  470.        
  471.         set 6,h
  472.        
  473.         ld d,0x28
  474.         dup 7
  475.         ld a,(de)
  476.         ld (hl),a
  477.         inc d
  478.         add hl,bc
  479.         edup
  480.         ld a,(de)
  481.         ld (hl),a
  482.        
  483.         pop hl
  484.         set 5,h
  485.        
  486.         ld d,0x30
  487.         push hl
  488.         dup 7
  489.         ld a,(de)
  490.         ld (hl),a
  491.         inc d
  492.         add hl,bc
  493.         edup
  494.         ld a,(de)
  495.         ld (hl),a
  496.         pop hl
  497.        
  498.         set 6,h
  499.        
  500.         ld d,0x38
  501.         dup 7
  502.         ld a,(de)
  503.         ld (hl),a
  504.         inc d
  505.         add hl,bc
  506.         edup
  507.         ld a,(de)
  508.         ld (hl),a
  509.        
  510.         pop hl
  511.         pop de
  512.         pop bc
  513.         inc de
  514.         inc hl
  515.         dec b
  516.         jp nz,emulVDPtiles1
  517.         pop hl
  518.         ld bc,40*8
  519.         add hl,bc
  520.         pop bc
  521.         dec b
  522.         jp nz,emulVDPtiles0
  523.        
  524.         if SPRITESON
  525. ;The Sprite Attribute Table occupies 128 bytes of VRAM from 1B00H to 1B7FH /3b00/. The table contains thirty-two four byte blocks, one for each sprite. The first block controls sprite 0 (the "top" sprite), the ;second controls sprite 1 and so on to sprite 31. The format of each block is as below:
  526.  
  527. ;   Vertical Position   Byte 0
  528. ;   Horizontal Position Byte 1
  529. ;   Pattern Number      Byte 2
  530. ;   EC  0       0       0       Colour Code(bits 3..0)  Byte 3
  531. ;In Byte 3, the Early Clock bit is normally 0 but will shift the sprite thirty-two pixels to the left when set to 1. This is so that sprites can slide in from the left of the screen, there being no spare coordinates in the horizontal direction.    
  532.  
  533. ;The Sprite Pattern Table occupies 2 KB of VRAM from 3800H to 3FFFH /1800/. It contains two hundred and fifty-six 8x8 pixel patterns, numbered from 0 to 255.
  534. ;AC
  535. ;BD
  536. ;8 bytes block A
  537. ;8 bytes block B
  538. ;8 bytes block C
  539. ;8 bytes block D
  540. ;for 16x16 sprites: pattern 0..3 = pattern 0, pattern 4..7 = pattern 1...
  541.         ld hl,0x4000+0x3B7F
  542. emulVDPsprites0
  543.         ld a,(hl) ;d3..0=colour code, d7=early clock (x-=32)
  544.         dec l
  545.         ld d,(hl) ;pattern number
  546.         dec l
  547.         ld c,(hl) ;x
  548.         dec l
  549.         ld b,(hl) ;y
  550.         or a
  551.         jp z,emulVDPsprites0_skip ;colour 0
  552.           inc b
  553.         ld a,b
  554.         cp 0xd1+1 ;???
  555.         jp nc,emulVDPsprites0_skip
  556.          srl c
  557.          srl c
  558.          srl c
  559.          ld a,c
  560.          add a,4
  561.          ld c,a
  562.          ;srl b
  563.          ;srl b
  564.          ;srl b
  565.          ld a,b
  566.          cp 24 *8
  567.          jp nc,emulVDPsprites0_skip
  568.         push hl
  569. ;bc=yx
  570.         ld a,c ;x
  571.         ld l,b ;y
  572.         ld h,0
  573.         ld b,h
  574.         ld c,l
  575.         add hl,hl
  576.         add hl,hl
  577.         add hl,bc ;*5
  578.          add hl,hl
  579.          add hl,hl
  580.          add hl,hl ;*40
  581.          ;add hl,hl
  582.          ;add hl,hl
  583.          ;add hl,hl
  584.         add a,l
  585.         ld l,a
  586.         ld a,h
  587.         adc a,0x80
  588.         ld h,a
  589.  
  590.         call setpgtiles4000
  591.  
  592.         ld bc,40
  593. ;d=pattern number
  594.         ld e,0
  595.          srl d
  596.          srl d ;pattern 0..3 = pattern 0, pattern 4..7 = pattern 1...
  597.         srl d
  598.         rr e
  599.         set 6,d ;ld d,0x40;+0x38 ;sprites
  600.         dup 8-1
  601.         push hl
  602.         SPRCOLUMN
  603.         pop hl
  604.         NEXTCOLUMN
  605.         edup
  606.         SPRCOLUMN
  607.        
  608.         call setpgcode4000
  609.        
  610.         pop hl
  611. emulVDPsprites0_skip
  612.         dec l
  613.         jp p,emulVDPsprites0
  614.        
  615.         endif
  616.  
  617.         call changescrpg
  618.        
  619.         call setpgcode8000c000
  620.         pop hl
  621.         pop de
  622.         pop bc
  623.        
  624. emulVDPsp=$+1
  625.         ld sp,0
  626. emulVDPjp=$+1
  627.         jp 0
  628.  
  629. pause
  630.         push af
  631.         push bc
  632.         push de
  633.         push hl
  634.         exx
  635.         ex af,af' ;'
  636.         push af
  637.         push bc
  638.         push de
  639.         push hl
  640.         push ix
  641.         push iy
  642.         YIELD
  643.         pop iy
  644.         pop ix
  645.         pop hl
  646.         pop de
  647.         pop bc
  648.         pop af
  649.         ex af,af' ;'
  650.         exx
  651.         pop hl
  652.         pop de
  653.         pop bc
  654.         pop af
  655.         ret
  656.  
  657.         if 1==0
  658. muztest
  659.         ei
  660.         halt
  661.         call L_9266 ;music player
  662.         jr muztest
  663.         endif
  664.  
  665. gentilemap
  666.         ld hl,0x5800
  667.         ld (hl),l
  668.         inc l
  669.         jr nz,$-2
  670.         inc h
  671.         ld (hl),l
  672.         inc l
  673.         jr nz,$-2
  674.         inc h
  675.         ld (hl),l
  676.         inc l
  677.         jr nz,$-2
  678.         ret
  679.  
  680. L0020
  681. ;DCOMPR
  682. ;Address  : #0020
  683. ;Function : Compares HL with DE
  684. ;Input    : HL, DE
  685. ;Output   : Z-flag set if HL and DE are equal. C-flag set if HL is less than DE.
  686. ;Registers: AF
  687.         push hl
  688.         or a
  689.         sbc hl,de
  690.         pop hl
  691.         ret
  692.  
  693. L003D
  694. ;???
  695. ;INIFNK
  696. ;Address  : #003E
  697. ;Function : Initialises the contents of the function keys
  698. ;Registers: All
  699.         ret
  700.  
  701. L0041
  702. ;DISSCR
  703. ;Address  : #0041
  704. ;Function : inhibits the screen display
  705. ;Registers: AF, BC
  706.         ret
  707.  
  708. L0044
  709. ;ENASCR
  710. ;Address  : #0044
  711. ;Function : displays the screen
  712. ;Registers: AF, BC
  713.         ret
  714.  
  715. L0047        
  716. ;WRTVDP
  717. ;Address  : #0047
  718. ;Function : write data in the VDP-register
  719. ;Input    : B  - data to write
  720. ;           C  - number of the register
  721. ;Registers: AF, BC
  722. ;can spoil bc
  723. ;TODO
  724.         ret
  725.  
  726. L004A
  727. ;RDVRM
  728. ;Address  : #004A
  729. ;Function : Reads the content of VRAM
  730. ;Input    : HL - address read
  731. ;Output   : A  - value which was read
  732. ;Registers: AF
  733.         push hl
  734.         set 6,h
  735.         ld a,(hl)
  736.         pop hl
  737.         ret
  738.  
  739. L004D
  740. ;WRTVRM
  741. ;Address  : #004D
  742. ;Function : Writes data in VRAM
  743. ;Input    : HL - address write (0..3fff)
  744. ;           A  - value write
  745. ;Registers: AF
  746.         push hl
  747.         set 6,h
  748.         ld (hl),a
  749.         pop hl
  750.         ret
  751.        
  752. L0056
  753. ;FILVRM
  754. ;Address  : #0056
  755. ;Function : fill VRAM with value
  756. ;Input    : A  - data byte
  757. ;           BC - length of the area to be written
  758. ;           HL - start address
  759. ;Registers: AF, BC
  760.         push bc
  761.         push hl
  762.         set 6,h
  763. FILVRM0
  764.         ld (hl),a
  765.         cpi
  766.         jp pe,FILVRM0
  767.         pop hl
  768.         pop bc ;unneeded?
  769.         ret
  770.  
  771. L0059
  772. ;LDIRMV
  773. ;Address  : #0059
  774. ;Function : Block transfer to memory from VRAM
  775. ;Input    : BC - blocklength
  776. ;           DE - Start address of memory
  777. ;           HL - Start address of VRAM
  778. ;Registers: All
  779.         push bc
  780.         push de
  781.         push hl
  782.         set 6,h
  783.         ldir
  784.         pop hl
  785.         pop de
  786.         pop bc ;unneeded?
  787.         ret
  788.  
  789. L005C        
  790. ;LDIRVM
  791. ;Address  : #005C
  792. ;Function : Block transfer to VRAM from memory
  793. ;Input    : BC - blocklength
  794. ;           DE - Start address of VRAM
  795. ;           HL - Start address of memory
  796. ;Registers: All
  797.         push bc
  798.         push de
  799.         push hl
  800.         set 6,d
  801.         ldir
  802.         pop hl
  803.         pop de
  804.         pop bc ;unneeded?
  805.         ret
  806.  
  807. L005F
  808. ;CHGMOD
  809. ;Address  : #005F
  810. ;Function : Switches to given screenmode
  811. ;Input    : A  - screen mode
  812. ;Registers: All
  813.         ret
  814.  
  815. L0062
  816. ;CHGCLR
  817. ;Address  : #0062
  818. ;Function : Changes the screencolors
  819. ;Input    : Foregroundcolor in FORCLR
  820. ;           Backgroundcolor in BAKCLR
  821. ;           Bordercolor in BDRCLR
  822. ;Registers: All
  823.         ret ;TODO
  824.      
  825. L0090
  826. ;GICINI
  827. ;Address  : #0090
  828. ;Function : Initialises PSG and sets initial value for the PLAY statement
  829. ;Registers: All
  830. shutay
  831.         push bc
  832.         push de
  833.         ld de,0xe00
  834. shutay0
  835.         dec d
  836.         ld bc,0xfffd
  837.         out (c),d
  838.         ld b,0xbf
  839.         out (c),e
  840.         jr nz,shutay0
  841.         pop de
  842.         pop bc
  843.         ret
  844.        
  845. L0093
  846. ;WRTPSG
  847. ;Address  : #0093
  848. ;Function : Writes data to PSG-register
  849. ;Input    : A  - PSG register number
  850. ;           E  - data write
  851.         push bc
  852.         ld bc,0xfffd
  853.         out (c),a
  854.         ld b,0xbf
  855.         out (c),e
  856.         pop bc
  857.         ret
  858.        
  859. L0096
  860. ;RDPSG
  861. ;Address  : #0096
  862. ;Function : Reads value from PSG-register
  863. ;Input    : A  - PSG-register read
  864. ;Output   : A  - value read
  865.         push bc
  866.         ld bc,0xfffd
  867.         out (c),a
  868.         in a,(c)
  869.         pop bc
  870.         ret
  871.  
  872. L00D5
  873. ;GTSTCK
  874. ;Address  : #00D5
  875. ;Function : Returns the joystick status
  876. ;Input    : A  - Joystick number to test (0 = cursors, 1 = port 1, 2 = port 2)
  877. ;Output   : A  - Direction (1 up, 3 right, 5 down, 7 left, 8 up-left)
  878. ;Registers: All
  879.         or a
  880.         jr nz,GTSTCK2
  881.        ld a,0xf7
  882.        in a,(0xfe)
  883.        bit 4,a
  884.         ld a,0xef
  885.         in a,(0xfe)
  886.        jr nz,$+4
  887.        res 1,a
  888.         rra
  889.         and 0x0f
  890.         ld hl,tstick
  891.         add a,l
  892.         ld l,a
  893.         jr nc,$+3
  894.         inc h
  895.         ld a,(hl)
  896.         ret
  897. tstick
  898. ;sinclair joystick 6789
  899.         ;db 0,0,0,0
  900.         ;db 0,6,8,7
  901.         ;db 0,4,2,3
  902.         ;db 0,5,1,0
  903. ;cursor joystick 6785
  904.         db 0,0,0,0
  905.         db 0,4,6,5
  906.         db 0,2,8,1
  907.         db 0,3,7,0
  908. GTSTCK2
  909.         xor a
  910.         ret
  911.  
  912. L00D8
  913. ;GTTRIG
  914. ;Address  : #00D8
  915. ;Function : Returns current trigger status
  916. ;Input    : A  - trigger button to test
  917. ;           0 = spacebar
  918. ;           1 = port 1, button A
  919. ;           2 = port 2, button A
  920. ;           3 = port 1, button B
  921. ;           4 = port 2, button B
  922. ;Output   : A  - #00 trigger button not pressed
  923. ;                #FF trigger button pressed
  924. ;Registers: AF
  925.         or a
  926.         jr nz,GTTRIG2
  927.         ld a,0x7f
  928.         in a,(0xfe)
  929.         cpl
  930.         rra
  931.         jr c,GTTRIGOK
  932.         ld a,0xef
  933.         in a,(0xfe)
  934.         cpl
  935.         rra
  936. GTTRIGOK
  937.         sbc a,a
  938.         ret
  939. GTTRIG2
  940.         xor a
  941.         ret
  942.  
  943. L0141
  944. ;SNSMAT
  945. ;Address  : #0141
  946. ;Function : Returns the value of the specified line from the keyboard matrix
  947. ;Input    : A  - for the specified line
  948. ;Output   : A  - for data (the bit corresponding to the pressed key will be 0)
  949. ;Registers: AF
  950.         cp 5
  951.         jr z,SNSMAT_5
  952.         cp 2
  953.         jr z,SNSMAT_2
  954.        if 1==0
  955.         push bc
  956.         ld a,0x7f
  957.         in a,(0xfe)
  958.         rrca
  959.         rrca
  960.         rrca
  961.         and 0xe0
  962.         ld c,a
  963.         ld a,0xfe
  964.         in a,(0xfe)
  965.         and 0x1f
  966.         or c
  967.         pop bc
  968.        else
  969. ;7:matrix RET,SELECT,BS,STOP,TAB,ESC,F5,F4 (SELECT,ESC needed)
  970.         ld a,(curkey)
  971.         cp key_enter
  972.         ld a,0xff-64 ;SELECT
  973.         ret z
  974.         ld a,(curkey)
  975.         cp key_esc
  976.         jr nz,SNSMAT_no
  977.         ld a,0xff-4 ;ESC
  978.        endif
  979.         ret
  980. SNSMAT_2
  981. ;matrix BA /.,`' (A needed)
  982.         ld a,0xfd
  983.         in a,(0xfe)
  984.         rrca
  985.         rrca
  986.         or 0xbf ;'A'
  987.         ret
  988. SNSMAT_5
  989. ;matrix ZYXWVUTS (Z,X needed)
  990.         ld a,0xfe
  991.         in a,(0xfe)
  992.         rra
  993.         rra ;'Z'
  994.         bit 0,a ;'X'
  995.         ld a,0xff
  996.         rra ;'Z'
  997.         ret nz
  998.         res 5,a ;'X'
  999.         ret
  1000. SNSMAT_no
  1001.         ld a,0xff
  1002.         ret
  1003.        
  1004. L0156
  1005. ;KILBUF
  1006. ;Address  : #0156
  1007. ;Function : Clear keyboard buffer
  1008. ;Registers: HL
  1009.         ret
  1010.  
  1011. setpgsscr8000c000
  1012.         call getuser_scr_low
  1013.         SETPG32KLOW
  1014.         call getuser_scr_high
  1015.         SETPG32KHIGH
  1016.         ret
  1017.  
  1018. getuser_scr_low
  1019. getuser_scr_low_patch=$+1
  1020. getuser_scr_low_patchN=0xff&(user_scr0_low^user_scr1_low)
  1021.         ld a,(user_scr1_low) ;ok
  1022.         ret
  1023.  
  1024. getuser_scr_high
  1025. getuser_scr_high_patch=$+1
  1026. getuser_scr_high_patchN=0xff&(user_scr0_high^user_scr1_high)
  1027.         ld a,(user_scr1_high) ;ok
  1028.         ret
  1029.  
  1030. changescrpg
  1031.         ld hl,getuser_scr_low_patch
  1032.         ld a,(hl)
  1033.         xor getuser_scr_low_patchN
  1034.         ld (hl),a
  1035.         ld hl,getuser_scr_high_patch
  1036.         ld a,(hl)
  1037.         xor getuser_scr_high_patchN
  1038.         ld (hl),a
  1039.         ld a,(curscrnum_int)
  1040.         xor 1
  1041.         ld (curscrnum_int),a
  1042.         ret
  1043.  
  1044. wasfont
  1045.         incbin "cga.bin"
  1046.  
  1047.         display $
  1048.         ds 0x2000-$
  1049.  
  1050.         include "ISITAR.ASM"
  1051.  
  1052. end
  1053.  
  1054.         display "End=",end
  1055.         ;display "Free after end=",/d,#c000-end
  1056.         display "Size ",/d,end-begin," bytes"
  1057.         savebin "isitar.com",begin,end-begin
  1058.         LABELSLIST "../../../us/user.l"
  1059.