Subversion Repositories NedoOS

Rev

Rev 775 | Rev 854 | 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.             ;IFN 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.                         ;выясним откуда запустились
  173. init_rst_buf=0x4000
  174.                         ld hl,init_rst_buf
  175.                         rst 0x08
  176.                         defb 0x50,0x03
  177.                         rst 0x08        ; в D вернется текущий драйв
  178.                         defb 0x50,0x02
  179.                         ld a,d
  180.                         add a,a
  181.                         add a,a
  182.                         add a,a
  183.                         ld hl,init_rst_buf
  184.                         ld b,0
  185.                         ld c,a
  186.                         add hl,bc
  187.                         ld de,init_rst_buf+512
  188.                         ld bc,8
  189.                         ldir
  190.                         ld a,(init_rst_buf+512)
  191.                         rst 0x08
  192.                         defb 0x50,0x05
  193.                         ld a,(init_rst_buf+512)
  194.                         and 1 ;m/s
  195.                         ld hl,init_rst_buf
  196.                         ld bc,0x0000
  197.                         ld d,b
  198.                         ld e,c
  199.                         ld a,2
  200.                         ex af,af' ;'
  201.                         ld a,1
  202.                         rst 0x08
  203.                         defb 0x50,0x04,0x02
  204.                         ld a,(init_rst_buf+512)
  205.                         ld d,12
  206.                         cp 0x0f
  207.                         jr z,.l3
  208.                         ld d,3
  209.                         cp 4
  210.                         jr z,.init_sysdev_part
  211.                         ld d,7
  212.                         cp 5
  213.                         jp nz,init_sysdev_end
  214. .init_sysdev_part
  215.                         ld hl,init_rst_buf+0x01BE+0x0008-12
  216. .l2
  217.                         inc d
  218.                         push de
  219.                         ld bc,12
  220.                         add hl,bc
  221.                         ld bc,0x0400
  222.                         ld de,init_rst_buf+512+3
  223. .l1                     ld a,(de)
  224.                         xor (hl)
  225.                         or c
  226.                         ld c,a
  227.                         inc de
  228.                         inc hl
  229.                         djnz .l1
  230.                         pop de
  231.                         or a
  232.                         jr nz,.l2
  233. .l3
  234.                         ld a,d
  235.                         ld (init_sysdrv_val),a
  236. init_sysdev_end
  237.                         halt
  238.                         ld bc,0xeff7
  239.                         ld a,0x80
  240.                         out (c),a
  241.                         ld a,0x10
  242.                         ld bc,0x7ffd
  243.                         out (c),a
  244.                         ld bc,0x01bf
  245.                         out (c),b
  246.                         LD A,0xa8;%10101000 ;320x200 mode
  247.                         ld bc,0xbd77    ;shadow ports and palette remain on
  248.                         out (c),a
  249.                         xor a
  250.                         out (0xbf),a
  251.                 else
  252.                         LD A,0xa8;%10101000 ;320x200 mode
  253.                         CALL INIT_OUTSHADON
  254.         endif
  255.         call INIT_blackpal
  256.  
  257.         di
  258.                 if atm==1 and PS2KBD
  259.                         ld bc,0xdef7   
  260.                         out (c),c              
  261.                         ld b,0xbe              
  262.                         ld a,2                 
  263.                         out (c),a
  264.                 endif
  265.                
  266.                 if atm==3 or atm==1
  267.                         ld a,0x7f-5
  268.                         ld bc,memportrom4000
  269.                         out (c),a ;отключаем 7ffd
  270.                         ld a,0x7f-2
  271.                         ld bc,memportrom8000
  272.                         out (c),a ;отключаем 7ffd
  273.                         ;ld a,0x7f-2
  274.                         ld bc,memportromc000
  275.                         out (c),a ;отключаем 7ffd
  276.                 endif
  277.        
  278.                 ifn atm==1
  279.                         call findpgdos
  280.                 else
  281.                         ld a,0x04
  282.                         in a,(0xbe)
  283.                         and 0xbf;%10111111
  284.                         ;ld a,0x8b
  285.                 endif
  286.         ld lx,a
  287.         ld (sys_pgdos),a ;до установки резидента
  288.  
  289.         ld a,pgsys
  290.         call INIT_setpg_c000
  291.         ld hl,0x8000
  292.         ld de,0xc000
  293.         ld bc,0x4000
  294.         ldir
  295.        
  296.         ld a,pgtrdosfs
  297.         call INIT_setpg_c000
  298.         ld hl,wastrdosfs
  299.         ld de,0xc000+idle;COMMANDLINE;PROGSTART ;idle code
  300.         ld bc,trdosfs_sz
  301.         ldir
  302.                         ld a,0xc3
  303.                         ld (0x5cc2),a
  304.                         ld hl,ONERR;ddrv
  305.                         ld (0x5cc3),hl
  306.                         ld hl,0x5c00
  307.                         ld de,0xc000+0x1c00
  308.                         ld bc,0x0400;for run hobeta;0x0200;0x5d3b-0x5c00
  309.                         ldir
  310.         ld hl,wasresident
  311.         ld de,resident+0xc000-0x4000
  312.         ld bc,resident_sz
  313.         ldir
  314.                         ld hl,0x5c4b
  315.                         ld de,varbas_stor+0x8000
  316.                         ld bc,32
  317.                         ldir
  318.        
  319.         ld hl,0xc000+trdos_fcbbuf-0x4000
  320.         ld d,h
  321.         ld e,l
  322.         inc de
  323.         ld bc,0x200*trdos_MAXFILES-1
  324.         ld (hl),l;0
  325.         ldir
  326.  
  327.         ;ld a,pgidle
  328.         ;call INIT_setpg_c000
  329.         ;ld hl,wasidle
  330.         ;ld de,0x0100+0xc000
  331.         ;ld bc,idle_sz
  332.         ;ldir
  333.        
  334.         ld a,pgsys
  335.         call INIT_setpg_8000
  336.         ld a,pgfatfs
  337.         call INIT_setpg_c000
  338.        
  339. ;перебрасываем 16K упакованный блок в 0xc000
  340.         ld hl,wassys+0x3fff
  341.         ld de,0xffff
  342.         ld bc,0x4000
  343.         lddr
  344. ;распаковываем в 0x6400
  345.         ld hl,0xc000;wassys
  346.         ld de,0x6400;0x8000
  347.         call DEC40 ;распаковываем в 0x8000 (там уже включены системные странички)
  348. ;перебрасываем 32K из 0x6400 в 0x8000
  349.         ld hl,0x6400+0x7fff
  350.         ld de,0x8000+0x7fff
  351.         ld bc,0x8000
  352.         lddr
  353.  
  354. fatfspatchaddr=0xc000
  355.        
  356.         ld hl,devices_init
  357.         ld (0xc000+FFS_DRV.init),hl
  358.         ld hl,disk_status
  359.         ld (0xc000+FFS_DRV.status),hl
  360.         ld hl,devices_read      ;read to userspace
  361.         ld (0xc000+FFS_DRV.rd_to_usp),hl
  362.         ld hl,devices_readnopg  ;read to buffer
  363.         ld (0xc000+FFS_DRV.rd_to_buf),hl
  364.         ld hl,devices_write     ;write from userspace
  365.         ld (0xc000+FFS_DRV.wr_fr_usp),hl
  366.         ld hl,devices_writenopg ;write from buffer
  367.         ld (0xc000+FFS_DRV.wr_fr_buf),hl
  368.         ld hl,get_fattime
  369.         ld (0xc000+FFS_DRV.RTC),hl
  370.         ld hl,strcpy_lib2usp   
  371.         ld (0xc000+FFS_DRV.strcpy_lib2usp),hl
  372.         ld hl,strcpy_usp2lib
  373.         ld (0xc000+FFS_DRV.strcpy_usp2lib),hl
  374.         ld hl,memcpy_lib2usp
  375.         ld (0xc000+FFS_DRV.memcpy_lib2usp),hl
  376.         ld hl,memcpy_usp2lib
  377.         ld (0xc000+FFS_DRV.memcpy_usp2lib),hl
  378.         ld hl,memcpy_buf2usp
  379.         ld (0xc000+FFS_DRV.memcpy_buf2usp),hl
  380.         ld hl,memcpy_usp2buf
  381.         ld (0xc000+FFS_DRV.memcpy_usp2buf),hl
  382.  
  383. ;инициализация менеджера памяти и вход в юзерспейс:
  384. ;HALT (чтобы прерывание не произошло когда не надо)
  385. ;[назначаем страницы системспейса (одна из них должна быть такая же, как в юзерспейсе) - уже есть общая страница 5]
  386. ;в юзерспейсе назначаем нижнюю страницу с керналем (вместо ПЗУ)
  387.         ld a,fd_user
  388.         out (0xfd),a
  389.                 if atm==3 or atm==1
  390.          ld a,0x7f
  391.          ld bc,memportrom0000
  392.          out (c),a ;отключаем ПЗУ
  393.          ld a,0x7f-5
  394.          ld bc,memportrom4000
  395.          out (c),a ;отключаем 7ffd
  396.          ld a,0x7f-2
  397.          ld bc,memportrom8000
  398.          out (c),a ;отключаем 7ffd
  399.          ;ld a,0x7f-2
  400.          ld bc,memportromc000
  401.          out (c),a ;отключаем 7ffd
  402.         endif
  403.         ld a,pgtrdosfs ;idle
  404.         ld bc,memport0000
  405.         out (c),a
  406.        
  407.         ;ld hl,wasuserkernel+0x8000
  408.         ;ld de,0
  409.         ;ld bc,userkernel_sz
  410.         ;ldir
  411.        
  412.         ld a,fd_system
  413.         out (0xfd),a
  414.                 if atm==3 or atm==1
  415.          ld a,0x7f
  416.          ld bc,memportrom0000
  417.          out (c),a ;отключаем ПЗУ
  418.          ;4000,8000,c000 уже отключили 7ffd выше
  419.         endif
  420.         ld a,pgsys
  421.         ld bc,memport0000
  422.         out (c),a
  423. ;в системспейсе:
  424. ;включить fatfs
  425. ;поставить резидент в 7fxx
  426. ;переходим в sys_intq, а оттуда в init_resident
  427.  
  428.         if 1==0
  429.         ld a,lx;(sys_pgdos)
  430.         ld bc,memportrom0000
  431.         out (c),a
  432.         LD A,0xa8;%10101000 ;320x200 mode
  433.         ld bc,0xff77 ;shadow ports off, palette off
  434.         out (c),a
  435.         ld a,1
  436.         ld c,1
  437.         call 0x3d13
  438.         ld c,0x18
  439.         call 0x3d13
  440.         ld hl,0xc000
  441.         ld de,0x0000
  442.         ld bc,0x0805
  443.         call 0x3d13
  444.         jr $
  445.         endif
  446.  
  447.         ld sp,BDOSSTACK
  448.         ;ei
  449.         ;halt ;чтобы прерывание не произошло когда не надо
  450.         ;di
  451.         ;jr $
  452. ;init_oldmousecoords=$+1
  453. ;        ld hl,0
  454. ;        ld (sys_oldmousecoords),hl
  455.          call BDOS_setpgstructs
  456.          ld hl,0xc000
  457.          ld de,0xc001
  458.          ld bc,0x3fff
  459.          ld (hl),l;0
  460.          ldir ;не помогло
  461. init_sysdrv_val=$+1
  462.          ld a,SYSDRV
  463.          ld (SYSDRV_VAL),a
  464.         jp setkernelpages_go ;di!!!
  465.        
  466.                 ifn atm==1
  467. INIT_OUTSHADON
  468.         ;LD BC,0xFF77 ;shadow ports remain off
  469.                         LD BC,0xBD77 ;shadow ports and palette remain on
  470.                         LD IX,10835
  471.                         PUSH IX
  472.                         JP 0x3D2F
  473.                 endif
  474.  
  475. INIT_setpg_low
  476.         LD BC,memportrom0000 ;page for 0x0000..0x3fff
  477.         OUT (C),A
  478.         ret
  479.  
  480. INIT_setpg_8000
  481.         LD BC,memport8000 ;page for 0x8000..0xbfff
  482.         OUT (C),A
  483.         ret
  484.  
  485. INIT_setpg_c000
  486.         LD BC,memportc000 ;page for 0xc000..0xffff
  487.         OUT (C),A
  488.         ret
  489.        
  490.                 if atm==2
  491. basvar
  492. .tape
  493.         defb 0xFF, 0x00, 0x00, 0x00, 0x0D, 0x05, 0x10, 0x0D, 0x0D, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
  494.         defb 0x01, 0x00, 0x06, 0x00, 0x0B, 0x00, 0x01, 0x00, 0x01, 0x00, 0x06, 0x00, 0x10, 0x00, 0x00, 0x00
  495.         defb 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFD, 0x7F, 0x3E, 0x14, 0xED, 0x79, 0xC3, 0x00, 0xC0
  496.         defb 0x18, 0xF4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x40, 0x00, 0xFF, 0xCC, 0x01, 0xFC, 0x5F, 0x00
  497.         defb 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x02, 0x07, 0x00, 0x00, 0xB4, 0x5D, 0x00, 0x00, 0x26
  498.         defb 0x5D, 0x26, 0x5D, 0x3B, 0x5D, 0xB4, 0x5D, 0x3A, 0x5D, 0xB5, 0x5D, 0xB5, 0x5D, 0xB3, 0x5D, 0x00
  499.         defb 0x00, 0xB7, 0x5D, 0xC3, 0x5D, 0xC3, 0x5D, 0x2D, 0x92, 0x5C, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00
  500.         defb 0x00, 0x00, 0x00, 0x00, 0xB6, 0x1A, 0x92, 0x00, 0x24, 0x01, 0x00, 0x58, 0xFF, 0x00, 0x00, 0x21
  501.         defb 0x00, 0x5B, 0x21, 0x17, 0x00, 0x40, 0xE0, 0x50, 0x21, 0x18, 0x21, 0x17, 0x01, 0x07, 0x00, 0x07
  502.         defb 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  503.         defb 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  504.         defb 0x00, 0x00, 0xFF, 0x5F, 0xFF, 0xFF, 0xF4, 0x09, 0xA8, 0x10, 0x4B, 0xF4, 0x09, 0xC4, 0x15, 0x53
  505.         defb 0x81, 0x0F, 0xC9, 0x49, 0x91, 0xF4, 0x09, 0xC4, 0x83, 0x83, 0x83, 0x83, 0x00, 0x00, 0x00, 0x35
  506.         defb 0x36, 0x31, 0x36, 0x0E, 0x00, 0x00, 0x03, 0x6B, 0x5E, 0x95, 0x5E, 0x00, 0x25, 0x73, 0x74, 0x73
  507.         defb 0x35, 0x2E, 0x31, 0x61, 0x20, 0x43, 0x00, 0xDB, 0x00, 0x25, 0x25, 0x03, 0x09, 0x00, 0x00, 0x00
  508.         defb 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x80, 0x08
  509.         defb 0x00, 0xC8, 0xFA, 0x5C, 0xFA, 0x5C, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00
  510.         defb 0xFF, 0x89, 0x5D, 0xFC, 0x5F, 0xFF, 0x3C, 0xAA, 0x00, 0x00, 0x01, 0x02, 0xFA, 0x5F, 0x03, 0x00
  511.         defb 0xFE, 0x0D, 0x80, 0x00, 0x00, 0xFF, 0xF4, 0x09, 0xA8, 0x10, 0x4B, 0xF4, 0x09, 0xC4, 0x15, 0x53
  512.         defb 0x81, 0x0F, 0xC4, 0x15, 0x52, 0xF4, 0x09, 0xC4, 0x15, 0x50, 0x80, 0x01, 0x00, 0x23, 0x00, 0xFD
  513.         defb 0xB0, 0x22, 0x36, 0x35, 0x33, 0x36, 0x38, 0x22, 0x3A, 0xF9, 0xC0, 0xB0, 0x22, 0x31, 0x35, 0x36
  514.         defb 0x31, 0x39, 0x22, 0x3A, 0xEA, 0x3A, 0xF7, 0x22, 0x62, 0x6F, 0x6F, 0x74, 0x20, 0x20, 0x20, 0x20
  515.         defb 0x22, 0x0D, 0x80, 0xF4, 0x5C, 0x01, 0x05, 0x2E, 0x21, 0x00, 0x60, 0xE5, 0xC3, 0x13, 0x3D, 0x0D
  516. .endtape
  517.         endif
  518.  
  519.                 ifn atm==1
  520. findpgdos
  521. ;если не найти страницу текущего доса, то на старых версиях ПЗУ ZX Evo не будет работать (в странице 0x83 почему-то не дос по умолчанию)
  522.         call crcdos
  523.         ld (doscrchi),de
  524.         ld (doscrclo),bc
  525.         ld lx,0x83
  526. findpgdos0
  527.         ld a,lx
  528.         call INIT_setpg_low
  529.         call crcdos
  530. doscrchi=$+1
  531.         ld hl,0
  532.         or a
  533.         sbc hl,de
  534.         jr nz,doscrcbad
  535. doscrclo=$+1
  536.         ld hl,0
  537.         or a
  538.         sbc hl,bc
  539.         jr nz,doscrcbad
  540.         ld a,lx
  541.         ret
  542. doscrcbad
  543.         ld a,lx
  544.         add a,4
  545.         ld lx,a
  546.         cp 0xc0
  547.         jr c,findpgdos0
  548.         ld a,0x83 ;not found
  549.         ret
  550. crcdos
  551.         ld hl,0x0000
  552.         ld bc,0
  553.         ld de,0
  554. crcdos0
  555.         ld a,d
  556.         add a,a
  557.         rl c
  558.         rl b
  559.         rl e
  560.         rl d
  561.         xor b
  562.         ld b,a
  563.         ld a,(hl)
  564.         xor c
  565.         ld c,a
  566.         inc hl
  567.         bit 6,h
  568.         jr z,crcdos0
  569.         ret
  570.                 endif
  571.  
  572. INIT_blackpal
  573.         LD HL,blackpalend
  574.         ;halt ;halt есть выше - убрано, чтобы не светилось ничего
  575.         LD DE,0xa80f ;0xab=6912 ;palette on, EGA, turbo
  576.         LD BC,0xBD77
  577.         OUT (C),D
  578. INIT_setpal0 LD A,E
  579.         and 7
  580.         BIT 3,E
  581.         OUT (0xFE),A
  582.         JR Z,$+4
  583.         OUT (0xF6),A
  584.         LD A,(HL)
  585.         DEC HL
  586.         ld b,(hl) ;DDp palette low bits
  587.         dec hl
  588.         ld c,0xff
  589.         OUT (c),a;(0xFF),A
  590.         DEC E
  591.         JP P,INIT_setpal0
  592.         ret
  593.  
  594.         ifdef NOPAL
  595.         dw 0xffff,0xfefe,0xfdfd,0xfcfc,0xefef,0xeeee,0xeded,0xecec
  596.         dw 0xffff,0xdede,0xbdbd,0x9c9c,0x6f6f,0x4e4e,0x2d2d,0x0c0c
  597.         else
  598.         ds 32,0xf3
  599.         endif
  600. blackpalend=$-1
  601.  
  602.         include "unmegalz.asm" ;DEC40
  603.  
  604. wasresident
  605.         disp resident
  606.                 ifn atm==1
  607. readmouse  ;=$-wasresident+resident
  608. ;sp=0x7fxx
  609. ;e=gfxmode
  610. ;out: hl=mousecoords, d=mousebuttons
  611.                         call sys_SHADOFF
  612.                        ;ifdef NOMOUSE
  613.                        ; ld hl,0
  614.                        ; ld d,0x0f ;buttons
  615.                        ;else
  616.                         ld bc,0xfadf ;buttons
  617.                         in d,(c)
  618.                         inc b ;ld bc,0xfbdf ;x
  619.                         in l,(c)
  620.                         ld b,0xff ;y
  621.                         in h,(c)
  622.                        ;endif
  623.                 endif
  624. shadon_pgsys  ;=$-wasresident+resident
  625.         LD A,e;0xa8;%10101000 ;320x200 mode
  626. shadon_pgsys_a  ;=$-wasresident+resident
  627.                 ifn atm==1
  628.                         CALL sys_SHADON
  629.                 else
  630.                         ld bc,0x01bf
  631.                         out (c),b
  632.                         ld bc,0xbd77    ;shadow ports and palette remain on
  633.                         out (c),a
  634.                         xor a
  635.                         out (0xbf),a
  636.                 endif
  637.                
  638.                 if atm==3 or atm==1
  639.                         ld a,0x7f
  640.                         call sys_setpg_low
  641.                         ld a,pgsys
  642.                         ld bc,memport0000
  643.                         jr sys_outca_jr
  644.          else
  645.                         ld a,0x7f-(pagexor-pgsys)
  646.          endif
  647. sys_setpg_low  ;=$-wasresident+resident
  648.                 ld bc,memportrom0000
  649.                 jr sys_outca_jr
  650. sys_SHADOFF  ;=$-wasresident+resident
  651. sys_pgdos=wasresident+(($+1)-resident) ;для патча
  652.                 ld a,0x83 ;48 basic switchable to DOS
  653.                 call sys_setpg_low
  654.         LD A,e;0xa8;%10101000 ;320x200 mode
  655.                 ld bc,0xff77 ;shadow ports off, palette off
  656. sys_outca_jr
  657.         out (c),a
  658.                 ret
  659.                 ifn atm==1
  660. sys_SHADON  ;=$-wasresident+resident
  661.                         LD bc,10835
  662.                         PUSH bc
  663.                         LD BC,0xBD77 ;shadow ports and palette remain on
  664.                         JP 0x3D2F
  665.                 endif
  666.  
  667. ;TODO убрать в pgtrdos
  668. dos3d13_resident  ;=$-wasresident+resident
  669.  
  670. ;сейчас включена pg5
  671. ;iy=23610
  672.         ld (dos3d13_sp_st),sp
  673.         ld sp,trdos_sp ;надо стек в 0x4000+ (не пересекающийся с INTSTACK, т.к. сейчас может произойти системное прерывание), по умолчанию стек был в 0x3fxx
  674.         ;call swap_sysvars
  675.         ex af,af'
  676.        call sys_SHADOFF ;включили ПЗУ
  677.                 ld (em3d13_de_st),de    ;push de ;e=gfxmode
  678.                  
  679.                 ;***************************** 
  680.                 ;call EM3D13PP;0x3d13
  681.                 ;собственно дpайвеp, аналогичный 0x3д13 (и с его использованием)
  682.                 ;на выходе - A pавно 0 - все окей, не 0 - ошибка
  683.                 ;вместо  пpоцедyp DRAW_WINDOWS, PRINT_WINDOWS и REST_WINDOW
  684.                 ;использyй свои.
  685.                 ;Kurleson
  686. ;EM3D13PP
  687.         ld      hl,em3d13pp_ret
  688.         push    hl
  689.         ld      (23613),sp
  690.         xor     a
  691.         ld (23801),a
  692.         ld      (23823),a
  693.         ld      (23824),a
  694.         ld hl,varbas_stor
  695.         ld de,0x5c4b
  696.         ld bc,32
  697.         ldir
  698.         if atm == 1
  699.                 xor a
  700.                 out (0xbf),a
  701.         endif
  702.         exx     ;pop hl,de,bc
  703.         ex af,af'
  704.         jp      0x3D13
  705.  
  706. ONERR
  707.         ex      (sp),hl
  708.         push    af
  709.         ld a,(0x5d0f)
  710.         or a
  711.         jr nz,em3d13pp_ret
  712.         ld      a,h
  713.         cp      0x0d
  714.         jr      z,em3d13_error
  715. ONERR_NO
  716.         pop     af
  717.         ex      (sp),hl
  718.         ret
  719. em3d13_error  
  720.         ld      a,0xff
  721.         ld (0x5d0f),a
  722. em3d13pp_ret
  723.  
  724. em3d13_de_st=$+1
  725.     ld de,0     ;e=gfxmode
  726.         di
  727.     call shadon_pgsys ;выключили ПЗУ (неатомарно - две записи в порт!!!)
  728.         ei
  729.         ;call swap_sysvars
  730. dos3d13_sp_st=$+1       ;-wasresident+resident
  731.         ld sp,0
  732.         ld a,(0x5d0f)   ;возврат ошибки
  733.         ret
  734.  
  735.         ifn atm==1
  736. NVRAM_REG=0xdf
  737. NVRAM_VAL=0xbf
  738. minmes  ;=$-wasresident+resident
  739.     ld h,a
  740.     xor a
  741.     srl h
  742.     rra
  743.     srl h
  744.     rra
  745.     srl h
  746.     rra
  747.     ret
  748.  
  749. bcd2bin  ;=$-wasresident+resident
  750.     ld b,NVRAM_REG
  751.     out (c),a
  752.     ld b,NVRAM_VAL
  753.     in a,(c)
  754.     ret
  755.    
  756. readtime  ;=$-wasresident+resident
  757. ;sp=0x7fxx
  758. ;e=gfxmode
  759. ;out: hl=date, de=time
  760. ;TODO атомарно
  761.         call sys_SHADOFF
  762.         LD A,e;0xa8;%10101000 ;320x200 mode
  763.         push af
  764.         ld bc,0xeff7
  765.         ld a,0x80
  766.         out (c),a
  767.         ld bc,0xf7 + (NVRAM_REG<<8)
  768.     ld a,0x0b
  769.     out (c),a
  770.     ld b,NVRAM_VAL
  771.     in a,(c)
  772.     or 0x04
  773.     out (c),a
  774.     xor a               ;sec
  775.     call bcd2bin
  776.     srl a
  777.     ld e,a
  778.    
  779.     ld a,2              ;min
  780.     call bcd2bin
  781.     call minmes
  782.     add a,e
  783.     ld e,a
  784.     ld d,h
  785.    
  786.     ld a,4              ;h
  787.     call bcd2bin
  788.     add a,a
  789.     add a,a
  790.     add a,a
  791.     add a,d
  792.     ld d,a
  793.    
  794.     ld a,7              ;day
  795.     call bcd2bin
  796.     ld l,a
  797.    
  798.     ld a,8              ;month
  799.     call bcd2bin
  800.     call minmes
  801.     add a,l
  802.     ld l,a
  803.    
  804.     ld a,9              ;year
  805.     call bcd2bin
  806.     add a,20
  807.     add a,a
  808.     add a,h
  809.     ld h,a
  810.         ld bc,0xeff7
  811.         xor a
  812.         out (c),a
  813.         pop af
  814.         jp shadon_pgsys_a
  815.                 endif
  816.  
  817.         ;disp $-wasresident+resident
  818.  
  819.                
  820.                 ds 100
  821. trdos_sp
  822. varbas_stor
  823.                 ds 32
  824.         ent
  825. resident_sz=$-wasresident
  826.         display "residentend=",resident+resident_sz,"<=",trdos_catbuf
  827.  
  828. wastrdosfs
  829.         disp COMMANDLINE;PROGSTART
  830. idle
  831.         db "idle",0
  832.         ds PROGSTART-$
  833.         include "idle.asm"
  834. idle_sz=$-idle
  835.         ent
  836.         disp 0x4000+idle+idle_sz
  837.         include "trdosfs.asm"
  838.         include "trdosio.asm"
  839.         include "bdospg2.asm"
  840.         ent
  841. trdosfs_sz=$-wastrdosfs
  842.         display "trdosfs_sz=",/h,trdosfs_sz,"<=0x1c00"
  843.        
  844. end
  845. wassys
  846.  
  847.         SLOT 0
  848.         page COMPILEPG_SYS0
  849.         SLOT 1
  850.         page COMPILEPG_SYS1
  851.         org 0x0000
  852. sysbegin
  853.         include "syskrnl.asm"
  854. wasuserkernel
  855.         disp 0x0000
  856.         include "userkrnl.asm"
  857.         ent
  858. userkernel_sz=$-wasuserkernel
  859.         ;display "wasuserkernel=",/d,wasuserkernel
  860.         ;display "wasuserkernel_end=",/d,$
  861.         ;display "userkernel_sz=",/d,userkernel_sz
  862.         ds 0x4000-$
  863.         incbin "../fatfs4os/fatfs.raw"
  864. sysend
  865.  
  866.         ;display "begin=",/d,begin
  867.         ;display "end=",/d,end
  868.        
  869.         ;display "sysbegin=",/d,sysbegin
  870.         ;display "sysend=",/d,sysend
  871.  
  872.         SLOT 1
  873.         page COMPILEPG_INIT
  874.         savebin "initcode.c",begin,end-begin
  875.        
  876.         SLOT 0
  877.         page COMPILEPG_SYS0
  878.         SLOT 1
  879.         page COMPILEPG_SYS1
  880.         savebin "syscode.c",sysbegin,sysend-sysbegin
  881.        
  882.         LABELSLIST "..\..\us\user.l"
  883.