Subversion Repositories NedoOS

Rev

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

  1.         DEVICE ZXSPECTRUM128
  2.         ;device pentagon1024
  3.  
  4.         include "../_sdk/syssets.asm"
  5. TOPDOWNMEM=0;1
  6.  
  7.                 if atm != 2
  8. memport0000=0x37f7
  9. memport4000=0x77f7
  10. memport8000=0xb7f7
  11. memportc000=0xf7f7
  12. memportrom0000=0x3ff7
  13. memportrom4000=0x7ff7
  14. memportrom8000=0xbff7
  15. memportromc000=0xfff7
  16. pagexor=0xff
  17.         else
  18. memport0000=0x3ff7
  19. memport4000=0x7ff7
  20. memport8000=0xbff7
  21. memportc000=0xfff7
  22. memportrom0000=0x3ff7
  23. memportrom4000=0x7ff7
  24. memportrom8000=0xbff7
  25. memportromc000=0xfff7
  26. pagexor=0x7f
  27.         endif
  28.        
  29.         if NEMOIDE==1
  30. ;схема Nemo:
  31. hddstat=0xF0
  32. hddcmd=0xF0
  33. hddhead=0xD0
  34. hddcylhi=0xB0
  35. hddcyllo=0x90
  36. hddsec=0x70
  37. hddcount=0x50
  38. hdderr=0x30
  39. hdddatlo=0x10
  40. hdddathi=0x11
  41. hddupr=0xC8
  42. hdduprON=0
  43.         else
  44. ;схема ATM:
  45. hddstat=0xFEEF
  46. hddcmd=0xFEEF
  47. hddhead=0xFECF
  48. hddcylhi=0xFEAF
  49. hddcyllo=0xFE8F
  50. hddsec=0xFE6F
  51. hddcount=0xFE4F
  52. hdderr=0xFE2F
  53. hdddatlo=0xFE0F
  54. hdddathi=0xFF0F
  55. hddupr=0xFEBE ;при установленном b7 FFBA
  56. hdduprON=0xFFBA
  57. hddupr1=0xF7
  58. hddupr0=0x77
  59.         endif
  60. memport8000_hi=memport8000/256
  61. memportc000_hi=memportc000/256
  62.  
  63. SYSMINSTACK=0x3b00
  64.  
  65. resident=0x6000;0x6000+8000 (где не затрут при очистке экрана) ;pgtrdosfs
  66. trdos_catbuf=0x6300;0x3200 ;,0x900 ;pgtrdosfs (0x4000)
  67. trdos_sectorbuf=0x6c00
  68. trdos_fcbbuf=0x6d00 ;size=0x200*trdos_MAXFILES
  69. trdos_MAXFILES=8
  70. INTMUZSTACK=0x3e00 ;kernelspace
  71. ;INTSTACK1=0x3f00 ;kernelspace (для входа в обработчик без порчи стека) (не пересекается с возможным стеком задачи!!!)
  72. INTSTACK2=0x5f00;0x6000 ;pgkillable и pgtrdosfs (рабочий стек обработчика прерываний) (>=0x4000, иначе нельзя выключить теневые порты)
  73. TRDOSSTACK=0x5f00-96;0x6000-96 ;чтобы не пересекалось с INTSTACK (в промежутке между преключениями страниц может произойти системное прерывание), но и на экран не попало
  74. BDOSSTACK=0x4000 ;kernelspace
  75. STACK=0x4000 ;userspace
  76. ;при вызове BDOS стек некоторое время такой же, как в юзерспейсе
  77. ;поэтому на входе в BDOS надо иметь в 0x4000...0xffff страницы, которые не жалко
  78. ;предполагается, что юзер не имеет стек ниже 0x3b00, иначе он затрёт систему
  79.  
  80.         include "../_sdk/sys_h.asm"
  81.  
  82.         if TOPDOWNMEM
  83. pgtrdosfs=pagexor-(sys_npages-1)
  84. pgfatfs=pagexor-(sys_npages-2)
  85. pgsys=pagexor-(sys_npages-3)
  86. pgfatfs2=pagexor-(sys_npages-4) ;structs
  87.         else
  88. pgtrdosfs=pagexor-8
  89. pgfatfs=pagexor-9
  90. pgsys=pagexor-10
  91. pgfatfs2=pagexor-11 ;structs
  92.         endif
  93.  
  94. pgkillable=pagexor-4 ;в 128K памяти, т.к. можно портить
  95. ;pgfirstfree=pagexor-11
  96.  
  97. pgscr0_0=pagexor-1
  98. pgscr0_1=pagexor-5
  99. pgscr1_0=pagexor-3
  100. pgscr1_1=pagexor-7
  101.  
  102. fd_system=0x57;%01010111 ;%0x01sx1x ;для неисправленного АТМ2 надо A9=1, а номер страницы в 0x7ffd не будет влиять, если адресация по memportc000
  103. fd_system_getchar=0x56;%01010110 ;%0x01sx1x ;для неисправленного АТМ2 надо A9=1, а номер страницы в 0x7ffd не будет влиять, если адресация по memportc000
  104. fd_user=0x47;%01000111 ;%0x00sx1x ;для неисправленного АТМ2 надо A9=1, а номер страницы в 0x7ffd не будет влиять, если адресация по memportc000
  105.  
  106. ;условные страницы для sjasm
  107. COMPILEPG_INIT=0
  108. COMPILEPG_SYS0=4
  109. COMPILEPG_SYS1=6
  110.  
  111.         SLOT 1
  112.         page COMPILEPG_INIT
  113.         org 0x6000
  114. begin
  115.         di
  116.         xor a
  117.         out (0xfe),a
  118.         ifdef KOE
  119.             display "KOE!!!"
  120.             ld a,0 ;turbo ;0x10 ;noturbo
  121.             ld bc,0xeff7
  122.             out (c),a ;for KOE
  123.             ld a,0x10
  124.             ld bc,0x7ffd
  125.             out (c),a
  126.         endif
  127.                 if atm==2
  128.             ld hl,basvar.tape
  129.             ld de,0x5c00
  130.             ld bc,basvar.endtape - basvar.tape
  131.             ldir
  132.             ld sp,0x5800
  133.             ld a,(0x3CBC)
  134.             cp 0x83
  135.             call z,0x3C9E
  136.             ;call 0x3d21
  137.         endif
  138.         LD (IY+1),0xCC
  139.  
  140.         if 1==0
  141.             ;IF em3d13
  142.             ; LD HL,ONERR
  143.             ; LD (23747),HL
  144.             ;ENDIF
  145.             LD A,(23833)
  146.             ADD A,'A'
  147.             LD (src),A
  148.             LD (dst),A
  149.             XOR A
  150.             LD (23658),A ;0x5c6a
  151.             ;LD L,A,H,L
  152.             ;LD (23802),HL
  153.         endif
  154.         XOR A
  155.         ld (0x5d10),a
  156.        
  157.         ;ld hl,0xc9f1 ;pop af:ret
  158.         ;ld (0x5cc2),hl
  159.        
  160.         ;ld bc,0xfbdf ;x
  161.         ;in l,(c)
  162.         ;ld b,0xff
  163.         ;in h,(c)
  164.         ;ld (init_oldmousecoords),hl
  165.  
  166. ;;;;;;;;;;;;;;;;;;; set gfx mode ;;;;;;;;;;;;;;;;;
  167.                 ei
  168.         halt
  169.         ;LD A,0xaa;%10101010 ;640x200 mode
  170.         ;LD A,0xae;%10101110 ;textmode
  171.                 if atm==1
  172. init_rst_buf=0x4000
  173.             ;проверим версию ers
  174.             ld d,0x00
  175.                         rst 0x08
  176.                         defb 0x4d,0x00
  177.             ld hl,-0x5812    ;ERS_MIN_VERSION 0.58.12
  178.             add hl,de
  179.             ld a,0xff
  180.             jr nc,.err_version
  181.                         ;выясним откуда запустились
  182.                         ld hl,init_rst_buf
  183.                         rst 0x08
  184.                         defb 0x50,0x03
  185.                         rst 0x08        ; в D вернется текущий драйв
  186.                         defb 0x50,0x02
  187.                         ld a,d
  188.                         add a,a
  189.                         add a,a
  190.                         add a,a
  191.                         ld hl,init_rst_buf
  192.                         ld b,0
  193.                         ld c,a
  194.                         add hl,bc
  195.                         ld de,init_rst_buf+512
  196.                         ld bc,8
  197.                         ldir
  198.                         ld a,(init_rst_buf+512)
  199.                         rst 0x08
  200.                         defb 0x50,0x05
  201.                         ld a,(init_rst_buf+512)
  202.                         and 1 ;m/s
  203.                         ld hl,init_rst_buf
  204.                         ld bc,0x0000
  205.                         ld d,b
  206.                         ld e,c
  207.                         ld a,2
  208.                         ex af,af' ;'
  209.                         ld a,1
  210.                         rst 0x08
  211.                         defb 0x50,0x04,0x02
  212.                         ld a,(init_rst_buf+512)
  213.                         ld d,12
  214.                         cp 0x0f
  215.                         jr z,.l3
  216.                         ld d,3
  217.                         cp 4
  218.                         jr z,.init_sysdev_part
  219.                         ld d,7
  220.                         cp 5
  221.                         jp nz,init_sysdev_end
  222. .init_sysdev_part
  223.                         ld hl,init_rst_buf+0x01BE+0x0008-12
  224. .l2
  225.                         inc d
  226.                         push de
  227.                         ld bc,12
  228.                         add hl,bc
  229.                         ld bc,0x0400
  230.                         ld de,init_rst_buf+512+3
  231. .l1                     ld a,(de)
  232.                         xor (hl)
  233.                         or c
  234.                         ld c,a
  235.                         inc de
  236.                         inc hl
  237.                         djnz .l1
  238.                         pop de
  239.                         or a
  240.                         jr nz,.l2
  241. .l3
  242.                         ld a,d
  243. .err_version
  244.                         ld (init_sysdrv_val),a
  245. init_sysdev_end
  246.                         halt
  247.                         ld bc,0xeff7
  248.                         ld a,0x80
  249.                         out (c),a
  250.                         ld a,0x10
  251.                         ld bc,0x7ffd
  252.                         out (c),a
  253.                         ld bc,0x01bf
  254.                         out (c),b
  255.                         LD A,0xa8;%10101000 ;320x200 mode
  256.                         ld bc,0xbd77    ;shadow ports and palette remain on
  257.                         out (c),a
  258.                         xor a
  259.                         out (0xbf),a
  260.                 else
  261.                         LD A,0xa8;%10101000 ;320x200 mode
  262.                         CALL INIT_OUTSHADON
  263.         endif
  264.         call INIT_blackpal
  265.  
  266.         di
  267.                 if atm==1 and PS2KBD
  268.                         ld bc,0xdef7   
  269.                         out (c),c              
  270.                         ld b,0xbe              
  271.                         ld a,2                 
  272.                         out (c),a
  273.                 endif
  274.                
  275.                 if atm==3 or atm==1
  276.                         ld a,0x7f-5
  277.                         ld bc,memportrom4000
  278.                         out (c),a ;отключаем 7ffd
  279.                         ld a,0x7f-2
  280.                         ld bc,memportrom8000
  281.                         out (c),a ;отключаем 7ffd
  282.                         ;ld a,0x7f-2
  283.                         ld bc,memportromc000
  284.                         out (c),a ;отключаем 7ffd
  285.                 endif
  286.        
  287.                 if atm != 1
  288.                         call findpgdos
  289.                 else
  290.                         ld a,0x04
  291.                         in a,(0xbe)
  292.                         and 0xbf;%10111111
  293.                         ;ld a,0x8b
  294.                 endif
  295.         ld lx,a
  296.         ld (sys_pgdos),a ;до установки резидента
  297.  
  298.         ld a,pgsys
  299.         call INIT_setpg_c000
  300.         ld hl,0x8000
  301.         ld de,0xc000
  302.         ld bc,0x4000
  303.         ldir
  304.        
  305.         ld a,pgtrdosfs
  306.         call INIT_setpg_c000
  307.         ld hl,wastrdosfs
  308.         ld de,0xc000+idle;COMMANDLINE;PROGSTART ;idle code
  309.         ld bc,trdosfs_sz
  310.         ldir
  311.         ld a,(init_sysdrv_val)  ;нужно для проверки версии ERS
  312.         ld (0xc000+idle+6),a    ;при неправильном ERS сисдир==0xff
  313.                         ld a,0xc3
  314.                         ld (0x5cc2),a
  315.                         ld hl,ONERR;ddrv
  316.                         ld (0x5cc3),hl
  317.                         ld hl,0x5c00
  318.                         ld de,0xc000+0x1c00
  319.                         ld bc,0x0400;for run hobeta;0x0200;0x5d3b-0x5c00
  320.                         ldir
  321.         ld hl,wasresident
  322.         ld de,resident+0xc000-0x4000
  323.         ld bc,resident_sz
  324.         ldir
  325.                         ld hl,0x5c4b
  326.                         ld de,varbas_stor+0x8000
  327.                         ld bc,32
  328.                         ldir
  329.        
  330.         ld hl,0xc000+trdos_fcbbuf-0x4000
  331.         ld d,h
  332.         ld e,l
  333.         inc de
  334.         ld bc,0x200*trdos_MAXFILES-1
  335.         ld (hl),l;0
  336.         ldir
  337.  
  338.         ;ld a,pgidle
  339.         ;call INIT_setpg_c000
  340.         ;ld hl,wasidle
  341.         ;ld de,0x0100+0xc000
  342.         ;ld bc,idle_sz
  343.         ;ldir
  344.        
  345.         ld a,pgsys
  346.         call INIT_setpg_8000
  347.         ld a,pgfatfs
  348.         call INIT_setpg_c000
  349.        
  350.         ;jr $
  351. ;перебрасываем 16K упакованный блок в 0xb000
  352.         ld hl,wassys+0x4fff
  353.         ld de,0xffff
  354.         ld bc,0x5000
  355.         lddr
  356. ;распаковываем в 0x6400
  357.         ld hl,0xb000;wassys
  358.         ld de,0x6400;0x8000
  359.         call DEC40 ;распаковываем в de (там уже включены системные странички)
  360. ;перебрасываем 32K из 0x6400 в 0x8000
  361.         ld hl,0x6400+0x7fff
  362.         ld de,0x8000+0x7fff
  363.         ld bc,0x8000
  364.         lddr
  365.  
  366. fatfspatchaddr=0xc000
  367.        
  368.         ld hl,devices_init
  369.         ld (0xc000+FFS_DRV.init),hl
  370.         ld hl,disk_status
  371.         ld (0xc000+FFS_DRV.status),hl
  372.         ld hl,devices_read      ;read to userspace
  373.         ld (0xc000+FFS_DRV.rd_to_usp),hl
  374.         ld hl,devices_readnopg  ;read to buffer
  375.         ld (0xc000+FFS_DRV.rd_to_buf),hl
  376.         ld hl,devices_write     ;write from userspace
  377.         ld (0xc000+FFS_DRV.wr_fr_usp),hl
  378.         ld hl,devices_writenopg ;write from buffer
  379.         ld (0xc000+FFS_DRV.wr_fr_buf),hl
  380.         ld hl,get_fattime
  381.         ld (0xc000+FFS_DRV.RTC),hl
  382.         ld hl,strcpy_lib2usp   
  383.         ld (0xc000+FFS_DRV.strcpy_lib2usp),hl
  384.         ld hl,strcpy_usp2lib
  385.         ld (0xc000+FFS_DRV.strcpy_usp2lib),hl
  386.         ld hl,memcpy_lib2usp
  387.         ld (0xc000+FFS_DRV.memcpy_lib2usp),hl
  388.         ld hl,memcpy_usp2lib
  389.         ld (0xc000+FFS_DRV.memcpy_usp2lib),hl
  390.         ld hl,memcpy_buf2usp
  391.         ld (0xc000+FFS_DRV.memcpy_buf2usp),hl
  392.         ld hl,memcpy_usp2buf
  393.         ld (0xc000+FFS_DRV.memcpy_usp2buf),hl
  394.  
  395. ;инициализация менеджера памяти и вход в юзерспейс:
  396. ;HALT (чтобы прерывание не произошло когда не надо)
  397. ;[назначаем страницы системспейса (одна из них должна быть такая же, как в юзерспейсе) - уже есть общая страница 5]
  398. ;в юзерспейсе назначаем нижнюю страницу с керналем (вместо ПЗУ)
  399.         ld a,fd_user
  400.         out (0xfd),a
  401.                 if atm==3 or atm==1
  402.          ld a,0x7f
  403.          ld bc,memportrom0000
  404.          out (c),a ;отключаем ПЗУ
  405.          ld a,0x7f-5
  406.          ld bc,memportrom4000
  407.          out (c),a ;отключаем 7ffd
  408.          ld a,0x7f-2
  409.          ld bc,memportrom8000
  410.          out (c),a ;отключаем 7ffd
  411.          ;ld a,0x7f-2
  412.          ld bc,memportromc000
  413.          out (c),a ;отключаем 7ffd
  414.         endif
  415.         ld a,pgtrdosfs ;idle
  416.         ld bc,memport0000
  417.         out (c),a
  418.        
  419.         ;ld hl,wasuserkernel+0x8000
  420.         ;ld de,0
  421.         ;ld bc,userkernel_sz
  422.         ;ldir
  423.        
  424.         ld a,fd_system
  425.         out (0xfd),a
  426.                 if atm==3 or atm==1
  427.          ld a,0x7f
  428.          ld bc,memportrom0000
  429.          out (c),a ;отключаем ПЗУ
  430.          ;4000,8000,c000 уже отключили 7ffd выше
  431.         endif
  432.         ld a,pgsys
  433.         ld bc,memport0000
  434.         out (c),a
  435. ;в системспейсе:
  436. ;включить fatfs
  437. ;поставить резидент в 7fxx
  438. ;переходим в sys_intq, а оттуда в init_resident
  439.  
  440.         if 1==0
  441.         ld a,lx;(sys_pgdos)
  442.         ld bc,memportrom0000
  443.         out (c),a
  444.         LD A,0xa8;%10101000 ;320x200 mode
  445.         ld bc,0xff77 ;shadow ports off, palette off
  446.         out (c),a
  447.         ld a,1
  448.         ld c,1
  449.         call 0x3d13
  450.         ld c,0x18
  451.         call 0x3d13
  452.         ld hl,0xc000
  453.         ld de,0x0000
  454.         ld bc,0x0805
  455.         call 0x3d13
  456.         jr $
  457.         endif
  458.  
  459.         ld sp,BDOSSTACK
  460.         ;ei
  461.         ;halt ;чтобы прерывание не произошло когда не надо
  462.         ;di
  463.         ;jr $
  464. ;init_oldmousecoords=$+1
  465. ;        ld hl,0
  466. ;        ld (sys_oldmousecoords),hl
  467.          call BDOS_setpgstructs
  468.          ld hl,0xc000
  469.          ld de,0xc001
  470.          ld bc,0x3fff
  471.          ld (hl),l;0
  472.          ldir ;не помогло
  473. init_sysdrv_val=$+1
  474.          ld a,SYSDRV
  475.          ld (SYSDRV_VAL),a
  476.         jp setkernelpages_go ;di!!!
  477.        
  478.                 if atm != 1
  479. INIT_OUTSHADON
  480.         ;LD BC,0xFF77 ;shadow ports remain off
  481.                         LD BC,0xBD77 ;shadow ports and palette remain on
  482.                         LD IX,10835
  483.                         PUSH IX
  484.                         JP 0x3D2F
  485.                 endif
  486.  
  487. INIT_setpg_low
  488.         LD BC,memportrom0000 ;page for 0x0000..0x3fff
  489.         OUT (C),A
  490.         ret
  491.  
  492. INIT_setpg_8000
  493.         LD BC,memport8000 ;page for 0x8000..0xbfff
  494.         OUT (C),A
  495.         ret
  496.  
  497. INIT_setpg_c000
  498.         LD BC,memportc000 ;page for 0xc000..0xffff
  499.         OUT (C),A
  500.         ret
  501.        
  502.                 if atm==2
  503. basvar
  504. .tape
  505.         defb 0xFF, 0x00, 0x00, 0x00, 0x0D, 0x05, 0x10, 0x0D, 0x0D, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
  506.         defb 0x01, 0x00, 0x06, 0x00, 0x0B, 0x00, 0x01, 0x00, 0x01, 0x00, 0x06, 0x00, 0x10, 0x00, 0x00, 0x00
  507.         defb 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFD, 0x7F, 0x3E, 0x14, 0xED, 0x79, 0xC3, 0x00, 0xC0
  508.         defb 0x18, 0xF4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x40, 0x00, 0xFF, 0xCC, 0x01, 0xFC, 0x5F, 0x00
  509.         defb 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x02, 0x07, 0x00, 0x00, 0xB4, 0x5D, 0x00, 0x00, 0x26
  510.         defb 0x5D, 0x26, 0x5D, 0x3B, 0x5D, 0xB4, 0x5D, 0x3A, 0x5D, 0xB5, 0x5D, 0xB5, 0x5D, 0xB3, 0x5D, 0x00
  511.         defb 0x00, 0xB7, 0x5D, 0xC3, 0x5D, 0xC3, 0x5D, 0x2D, 0x92, 0x5C, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00
  512.         defb 0x00, 0x00, 0x00, 0x00, 0xB6, 0x1A, 0x92, 0x00, 0x24, 0x01, 0x00, 0x58, 0xFF, 0x00, 0x00, 0x21
  513.         defb 0x00, 0x5B, 0x21, 0x17, 0x00, 0x40, 0xE0, 0x50, 0x21, 0x18, 0x21, 0x17, 0x01, 0x07, 0x00, 0x07
  514.         defb 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  515.         defb 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  516.         defb 0x00, 0x00, 0xFF, 0x5F, 0xFF, 0xFF, 0xF4, 0x09, 0xA8, 0x10, 0x4B, 0xF4, 0x09, 0xC4, 0x15, 0x53
  517.         defb 0x81, 0x0F, 0xC9, 0x49, 0x91, 0xF4, 0x09, 0xC4, 0x83, 0x83, 0x83, 0x83, 0x00, 0x00, 0x00, 0x35
  518.         defb 0x36, 0x31, 0x36, 0x0E, 0x00, 0x00, 0x03, 0x6B, 0x5E, 0x95, 0x5E, 0x00, 0x25, 0x73, 0x74, 0x73
  519.         defb 0x35, 0x2E, 0x31, 0x61, 0x20, 0x43, 0x00, 0xDB, 0x00, 0x25, 0x25, 0x03, 0x09, 0x00, 0x00, 0x00
  520.         defb 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x80, 0x08
  521.         defb 0x00, 0xC8, 0xFA, 0x5C, 0xFA, 0x5C, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00
  522.         defb 0xFF, 0x89, 0x5D, 0xFC, 0x5F, 0xFF, 0x3C, 0xAA, 0x00, 0x00, 0x01, 0x02, 0xFA, 0x5F, 0x03, 0x00
  523.         defb 0xFE, 0x0D, 0x80, 0x00, 0x00, 0xFF, 0xF4, 0x09, 0xA8, 0x10, 0x4B, 0xF4, 0x09, 0xC4, 0x15, 0x53
  524.         defb 0x81, 0x0F, 0xC4, 0x15, 0x52, 0xF4, 0x09, 0xC4, 0x15, 0x50, 0x80, 0x01, 0x00, 0x23, 0x00, 0xFD
  525.         defb 0xB0, 0x22, 0x36, 0x35, 0x33, 0x36, 0x38, 0x22, 0x3A, 0xF9, 0xC0, 0xB0, 0x22, 0x31, 0x35, 0x36
  526.         defb 0x31, 0x39, 0x22, 0x3A, 0xEA, 0x3A, 0xF7, 0x22, 0x62, 0x6F, 0x6F, 0x74, 0x20, 0x20, 0x20, 0x20
  527.         defb 0x22, 0x0D, 0x80, 0xF4, 0x5C, 0x01, 0x05, 0x2E, 0x21, 0x00, 0x60, 0xE5, 0xC3, 0x13, 0x3D, 0x0D
  528. .endtape
  529.         endif
  530.  
  531.                 if atm != 1
  532. findpgdos
  533. ;если не найти страницу текущего доса, то на старых версиях ПЗУ ZX Evo не будет работать (в странице 0x83 почему-то не дос по умолчанию)
  534.         call crcdos
  535.         ld (doscrchi),de
  536.         ld (doscrclo),bc
  537.         ld lx,0x83
  538. findpgdos0
  539.         ld a,lx
  540.         call INIT_setpg_low
  541.         call crcdos
  542. doscrchi=$+1
  543.         ld hl,0
  544.         or a
  545.         sbc hl,de
  546.         jr nz,doscrcbad
  547. doscrclo=$+1
  548.         ld hl,0
  549.         or a
  550.         sbc hl,bc
  551.         jr nz,doscrcbad
  552.         ld a,lx
  553.         ret
  554. doscrcbad
  555.         ld a,lx
  556.         add a,4
  557.         ld lx,a
  558.         cp 0xc0
  559.         jr c,findpgdos0
  560.         ld a,0x83 ;not found
  561.         ret
  562. crcdos
  563.         ld hl,0x0000
  564.         ld bc,0
  565.         ld de,0
  566. crcdos0
  567.         ld a,d
  568.         add a,a
  569.         rl c
  570.         rl b
  571.         rl e
  572.         rl d
  573.         xor b
  574.         ld b,a
  575.         ld a,(hl)
  576.         xor c
  577.         ld c,a
  578.         inc hl
  579.         bit 6,h
  580.         jr z,crcdos0
  581.         ret
  582.                 endif
  583.  
  584. INIT_blackpal
  585.         LD HL,blackpalend
  586.         ;halt ;halt есть выше - убрано, чтобы не светилось ничего
  587.         LD DE,0xa80f ;0xab=6912 ;palette on, EGA, turbo
  588.         LD BC,0xBD77
  589.         OUT (C),D
  590. INIT_setpal0 LD A,E
  591.         and 7
  592.         BIT 3,E
  593.         OUT (0xFE),A
  594.         JR Z,$+4
  595.         OUT (0xF6),A
  596.         LD A,(HL)
  597.         DEC HL
  598.         ld b,(hl) ;DDp palette low bits
  599.         dec hl
  600.         ld c,0xff
  601.         OUT (c),a;(0xFF),A
  602.         DEC E
  603.         JP P,INIT_setpal0
  604.         ret
  605.  
  606.         ifdef NOPAL
  607.         dw 0xffff,0xfefe,0xfdfd,0xfcfc,0xefef,0xeeee,0xeded,0xecec
  608.         dw 0xffff,0xdede,0xbdbd,0x9c9c,0x6f6f,0x4e4e,0x2d2d,0x0c0c
  609.         else
  610.         ds 32,0xf3
  611.         endif
  612. blackpalend=$-1
  613.  
  614.         include "unmegalz.asm" ;DEC40
  615.  
  616. wasresident
  617.         disp resident
  618.                 if atm != 1
  619. readmouse  ;=$-wasresident+resident
  620. ;sp=0x7fxx
  621. ;e=gfxmode
  622. ;out:
  623. ;a=gfxmode, hl=mousecoords, d=mousebuttons, e=kempstonbuttons
  624.                         call sys_SHADOFF
  625.                        ;ifdef NOMOUSE
  626.                        ; ld hl,0
  627.                        ; ld d,0x0f ;buttons
  628.                        ;else
  629.                         ld bc,0xfadf ;buttons
  630.                         in d,(c)
  631.                         inc b ;ld bc,0xfbdf ;x
  632.                         in l,(c)
  633.                         ld b,0xff ;y
  634.                         in h,(c)
  635.                         ld c,0x1f
  636.                         in e,(c) ;kempstonbuttons
  637.                         inc e
  638.                         jr nz,$+3 ;0xff = kempston joystick absent
  639.                          inc e ;will be 0 after dec
  640.                         dec e
  641.                         jr shadon_pgsys_a
  642.                        ;endif
  643.                 endif
  644. shadon_pgsys  ;=$-wasresident+resident
  645.         LD A,e;0xa8;%10101000 ;320x200 mode
  646. shadon_pgsys_a  ;=$-wasresident+resident
  647.                 if atm != 1
  648.                         CALL sys_SHADON
  649.                 else
  650.                         ld bc,0x01bf
  651.                         out (c),b
  652.                         ld bc,0xbd77    ;shadow ports and palette remain on
  653.                         out (c),a
  654.                         xor a
  655.                         out (0xbf),a
  656.                 endif
  657.                
  658.                 if atm==3 or atm==1
  659.                         ld a,0x7f
  660.                         call sys_setpg_low
  661.                         ld a,pgsys
  662.                         ld bc,memport0000
  663.                         jr sys_outca_jr
  664.          else
  665.                         ld a,0x7f-(pagexor-pgsys)
  666.          endif
  667. sys_setpg_low  ;=$-wasresident+resident
  668.                 ld bc,memportrom0000
  669.                 jr sys_outca_jr
  670. sys_SHADOFF  ;=$-wasresident+resident
  671. sys_pgdos=wasresident+(($+1)-resident) ;для патча
  672.                 ld a,0x83 ;48 basic switchable to DOS
  673.                 call sys_setpg_low
  674.         LD A,e;0xa8;%10101000 ;320x200 mode
  675.                 ld bc,0xff77 ;shadow ports off, palette off
  676. sys_outca_jr
  677.         out (c),a
  678.                 ret
  679.                 if atm != 1
  680. sys_SHADON  ;=$-wasresident+resident
  681.                         LD bc,10835
  682.                         PUSH bc
  683.                         LD BC,0xBD77 ;shadow ports and palette remain on
  684.                         JP 0x3D2F
  685.                 endif
  686.  
  687. ;TODO убрать в pgtrdos
  688. dos3d13_resident  ;=$-wasresident+resident
  689.  
  690. ;сейчас включена pg5
  691. ;iy=23610
  692.         ld (dos3d13_sp_st),sp
  693.         ld sp,trdos_sp ;надо стек в 0x4000+ (не пересекающийся с INTSTACK, т.к. сейчас может произойти системное прерывание), по умолчанию стек был в 0x3fxx
  694.         ;call swap_sysvars
  695.         ex af,af' ;'
  696.         call sys_SHADOFF ;включили ПЗУ
  697.                 ld (em3d13_de_st),de    ;push de ;e=gfxmode
  698.                  
  699.                 ;***************************** 
  700.                 ;call EM3D13PP;0x3d13
  701.                 ;собственно дpайвеp, аналогичный 0x3д13 (и с его использованием)
  702.                 ;на выходе - A pавно 0 - все окей, не 0 - ошибка
  703.                 ;вместо  пpоцедyp DRAW_WINDOWS, PRINT_WINDOWS и REST_WINDOW
  704.                 ;использyй свои.
  705.                 ;Kurleson
  706. ;EM3D13PP
  707.         ld      hl,em3d13pp_ret
  708.         push    hl
  709.         ld      (23613),sp
  710.         xor     a
  711.         ld (23801),a
  712.         ld      (23823),a
  713.         ld      (23824),a
  714.         ld hl,varbas_stor
  715.         ld de,0x5c4b
  716.         ld bc,32
  717.         ldir
  718.         if atm == 1
  719.                 xor a
  720.                 out (0xbf),a
  721.         endif
  722.         exx     ;pop hl,de,bc
  723.         ex af,af' ;'
  724.         jp      0x3D13
  725.  
  726. ONERR
  727.         ex      (sp),hl
  728.         push    af
  729.         ld a,(0x5d0f)
  730.         or a
  731.         jr nz,em3d13pp_ret
  732.         ld      a,h
  733.         cp      0x0d
  734.         jr      z,em3d13_error
  735. ONERR_NO
  736.         pop     af
  737.         ex      (sp),hl
  738.         ret
  739. em3d13_error  
  740.         ld      a,0xff
  741.         ld (0x5d0f),a
  742. em3d13pp_ret
  743.  
  744. em3d13_de_st=$+1
  745.     ld de,0     ;e=gfxmode
  746.         di
  747.     call shadon_pgsys ;выключили ПЗУ (неатомарно - две записи в порт!!!)
  748.         ei
  749.         ;call swap_sysvars
  750. dos3d13_sp_st=$+1       ;-wasresident+resident
  751.         ld sp,0
  752.         ld a,(0x5d0f)   ;возврат ошибки
  753.         ret
  754.  
  755.         if atm != 1
  756. NVRAM_REG=0xdf
  757. NVRAM_VAL=0xbf
  758. minmes  ;=$-wasresident+resident
  759.     ld h,a
  760.     xor a
  761.     srl h
  762.     rra
  763.     srl h
  764.     rra
  765.     srl h
  766.     rra
  767.     ret
  768.  
  769. bcd2bin  ;=$-wasresident+resident
  770.     ld bc,0xf7 + (NVRAM_REG<<8)
  771.     out (c),a
  772.     ld b,NVRAM_VAL
  773.     in a,(c)
  774.     ld b,a
  775.     and 0xf0
  776.     rra ;*8
  777.     ld c,a ;*8
  778.     rra ;*4
  779.     rra ;*2
  780.     add a,c ;*10
  781.     res 7,b
  782.     res 6,b
  783.     res 5,b
  784.     res 4,b
  785.     add a,b
  786.     ret
  787.    
  788. readtime  ;=$-wasresident+resident
  789. ;sp=0x7fxx
  790. ;e=gfxmode
  791. ;out: hl=date, de=time
  792. ;TODO атомарно
  793.         call sys_SHADOFF
  794.         LD A,e;0xa8;%10101000 ;320x200 mode
  795.         push af
  796.         ld bc,0xeff7
  797.         ld a,0x80
  798.         out (c),a
  799.         ;ld bc,0xf7 + (NVRAM_REG<<8)
  800.     ;ld a,0x0b
  801.     ;out (c),a
  802.     ;ld b,NVRAM_VAL
  803.     ;in a,(c)
  804.     ;or 0x04
  805.     ;out (c),a
  806.     xor a               ;sec
  807.     call bcd2bin
  808.     srl a
  809.     ld e,a
  810.    
  811.     ld a,2              ;min
  812.     call bcd2bin
  813.     call minmes
  814.     add a,e
  815.     ld e,a
  816.     ld d,h
  817.    
  818.     ld a,4              ;h
  819.     call bcd2bin
  820.     add a,a
  821.     add a,a
  822.     add a,a
  823.     add a,d
  824.     ld d,a
  825.    
  826.     ld a,7              ;day
  827.     call bcd2bin
  828.     ld l,a
  829.    
  830.     ld a,8              ;month
  831.     call bcd2bin
  832.     call minmes
  833.     add a,l
  834.     ld l,a
  835.    
  836.     ld a,9              ;year
  837.     call bcd2bin
  838.     add a,20
  839.     add a,a
  840.     add a,h
  841.     ld h,a
  842.         ld bc,0xeff7
  843.         xor a
  844.         out (c),a
  845.         pop af
  846.         jp shadon_pgsys_a
  847.                 endif
  848.  
  849.         ;disp $-wasresident+resident
  850.  
  851.                
  852.                 ds 100
  853. trdos_sp
  854. varbas_stor
  855.                 ds 32
  856.         ent
  857. resident_sz=$-wasresident
  858.         display "residentend=",resident+resident_sz,"<=",trdos_catbuf
  859.  
  860. wastrdosfs
  861.         disp COMMANDLINE;PROGSTART
  862. idle
  863.         db "idle",0
  864.         ds PROGSTART-$
  865.         include "idle.asm"
  866. idle_sz=$-idle
  867.         ent
  868.         disp 0x4000+idle+idle_sz
  869.         include "trdosfs.asm"
  870.         include "trdosio.asm"
  871.         include "bdospg2.asm"
  872.         ent
  873. trdosfs_sz=$-wastrdosfs
  874.         display "trdosfs_sz=",/h,trdosfs_sz,"<=0x1c00"
  875.        
  876. end
  877. wassys
  878.  
  879.         SLOT 0
  880.         page COMPILEPG_SYS0
  881.         SLOT 1
  882.         page COMPILEPG_SYS1
  883.         org 0x0000
  884. sysbegin
  885.         include "syskrnl.asm"
  886. wasuserkernel
  887.         disp 0x0000
  888.         include "userkrnl.asm"
  889.         ent
  890. userkernel_sz=$-wasuserkernel
  891.         ;display "wasuserkernel=",/d,wasuserkernel
  892.         ;display "wasuserkernel_end=",/d,$
  893.         ;display "userkernel_sz=",/d,userkernel_sz
  894.         ds 0x4000-$
  895.         incbin "../fatfs4os/fatfs.raw"
  896. sysend
  897.  
  898.         ;display "begin=",/d,begin
  899.         ;display "end=",/d,end
  900.        
  901.         ;display "sysbegin=",/d,sysbegin
  902.         ;display "sysend=",/d,sysend
  903.  
  904.         SLOT 1
  905.         page COMPILEPG_INIT
  906.         savebin "initcode.c",begin,end-begin
  907.        
  908.         SLOT 0
  909.         page COMPILEPG_SYS0
  910.         SLOT 1
  911.         page COMPILEPG_SYS1
  912.         savebin "syscode.c",sysbegin,sysend-sysbegin
  913.        
  914.         LABELSLIST "..\..\us\user.l"
  915.