Середовище програмування MADL

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » Середовище програмування MADL » КР-580 » SAS Emulator. ВихКод. FASM


SAS Emulator. ВихКод. FASM

Сообщений 1 страница 22 из 22

1

SAS Emulator. ВихКод. FASM

Тема "SAS Emulator (эмулятор «ПК-01 Львов»)" на форумі kolibrios.org
http://board.kolibrios.org/viewtopic.php?t=3253

SOURCE_EMUL.7z
http://board.kolibrios.org/download/file.php?id=7740

2

Main.asm

Код:
use32       ; включить 32-битный режим ассемблера
org    0x0	   ; адресация с нуля
db     'MENUET01'  ; 8-байтный идентификатор MenuetOS
dd     0x01	   ; версия заголовка (всегда 1)
dd     START	   ; адрес первой команды
dd     I_END	   ; размер программы
dd 1700000;1693100;1700000;1677721;2097152;0x200000;0x1000000	    ; количество памяти
dd 1700000;1693100;1677721;2097152;0x200000;0x1000000	    ; адрес вершины стэка
dd     0x0	   ; адрес буфера для параметров
dd     0x0	   ; зарезервировано
	include 'uLVComp.asm'
	include 'uKeyBoard.asm'
	include 'uMem.asm'
	include 'uDrawScreen.asm'
	include 'ui8080.asm'
	include 'MACROS.INC'
  include 'Main2.asm'
  include 'scancodeLV.asm'
;---------------------------------------------------------------------
EmulEngineTimer0: ; основной движок без таймера
       mov eax,[opcodes_to_run]
       mov [i8080_do_opcodes_nb_cycles],eax
       call i8080_do_opcodes
      call draw_screen
	    ret

EmulEngineTimer1:
; для KOS 2 место;
; Extr_KlbrInWin.bat Нормально! 2 место
;QEMU - завал полный
      Call EmulEngineTimer0
      call Timer1
	ret

EmulEngineTimer2:
; для KOS 2 грузит проц не годится;
; Extr_KlbrInWin.bat немного грузит проце 3 место
; QEMU - нормально

Call Timer2
mov eax,[Timer2_result]
Cmp eax, [PlatoonTimer2T]
jb EmulEngineTimer2_ret
call PlatoonTimer2 ; взвод таймера
      Call EmulEngineTimer0
EmulEngineTimer2_ret:
ret

EmulEngineTimer3:
; ; для KOS 1 место;
;Extr_KlbrInWin.bat 1 место
;QEMU - завал полный
      Call EmulEngineTimer0
      call Timer3
	ret


START:
Call INITmain ; инициализация всего
;mov [rgPC],$0000c000 ; rgPC:=$C000;
CycleProgram: ; метка цикла программы:
call CycleProcesEvents ;  ЦИКЛ ОБРАБОТКИ СОБЫТИЙ
cmp [fPause],0
jnz CycleProgram_m1; ПАУЗА
 
;_case_TimerNumber_of:
  mov eax,[TimerNumber]
 Call dword [eax*4+TimerAdrs]
 
CycleProgram_m2:
;mov dword [@FLagExit],1  ; в случает когда нужен будет выход
cmp byte [@FLagExit],0
jz CycleProgram ;
   mov EAX, -1      ; иначе конец программы
jmp CycleProgram

; ПАУЗА
CycleProgram_m1:
; перерисовка экрана
inc dword [CountPause]
cmp [CountPause],50;25  
    Jnz p_m1 
 call draw_screen
 mov [CountPause],0    
p_m1:
 ; цвет меняем
 add [ColorPause],1234567
 and [ColorPause],$FFFFFF
    mov  ebx,[WindowSizeX]
    shr ebx,1
    shl ebx,16
    mov  eax,[WindowSizeY]
    shr eax,1
    add  ebx,eax ;15*65536+10
    mov ecx, [ColorPause] 
    mov  edx, textPause
    mov  esi, 8
    mov  eax, 4 
    mcall
    call Timer3
jmp CycleProgram_m2;
textPause db 'Pause...',0

I_END:           ; метка конца программы
ColorPause dd 0
CountPause dd 0
;!!!!!!!! Чтобы место не занимал
VideoDirtyM rb 16385
ImageData rd (256*3 * 256 * 2) ; сюда рисовать перед выводом на экран
 kbd_baseM rb 9; // массивы опроса клавиатуры
 kbd_extM rb 5;//=(1,2,3,4,5);
;;{ДЛЯ i8080_do_opcodes }
tmp3 rd 1
tmp2 rd 1
tmp1 rd 1
opcode rd 1
clock rd 1
i8080_do_opcodes_nb_cycles  rd 1
m28m_Result rd 1
m29m_Result rd 1
m30m_Result rd 1
m36m_a rd 1
m37m_a rd 1
m38m_Result rd 1
m39m_Result rd 1
m40m_a rd 1
m41m_a rd 1
m42m_a rd 1
m43m_a rd 1
m44m_a rd 1
m46m_Result rd 1
m53m_Result rd 1
m54m_Result rd 1
m55m_Result rd 1
m57m_Result rd 1
m58m_Result rd 1
m59m_Result rd 1
m60m_Result rd 1
m61m_a rd 1
m62m_a rd 1
m63m_a rd 1
m64m_a rd 1
m67m_a rd 1
mD7m_a rd 1
m70m_a rd 1
m73m_a rd 1
m71m_a rd 1
m79m_Result rd 1
m84m_a rd 1
m85m_a rd 1
m86m_a rd 1
m87m_a rd 1
m88m_a rd 1
m89m_a rd 1
m90m_a rd 1
m91m_a rd 1
m92m_a rd 1
mA1m_Result rd 1
mA5m_a rd 1
mA6m_a rd 1
mB4m_a1 rd 1
mB4m_a2 rd 1
mB6m_a rd 1
mB7m_a rd 1
mB8m_Result rd 1
mB9m_Result rd 1

 adrs rd 256 ;= Таблица Case of opcode
 TableGraphicsMode rd 3 ;
 TableDrawScreenPR rd 3
 TableKeyDop rd 256
 TableKeyOsnEngl rd 256
 TableKeyOsnRus  rd 256
 TableMy_col2 rd 4
 TableSupCol2 rd 5
 WindowSizeX rd 1 ; размеры окна
 WindowSizeY rd 1  ; размеры окна

3

Main2.asm

Код:
titleE:      db   'Games in SAS emulator 1.0 beta',0
@FLagExit: rd  1; // флаг выхода из программы (заглушка для выхода)
macro INT0x40 { int 0x40 }
CycleProcesEvents: ;  ЦИКЛ ОБРАБОТКИ СОБЫТИЙ
Mov eax, 11 ;Функция 11 - проверить, есть ли событие, без ожидания. =======
INT0x40
cmp  eax,0
je CycleProcesEvents_ret
;    mcall 10            ; функция 10 - ждать события
    cmp  eax,1    ; перерисовать окно ?
    je	DrawWindow     ; перерисовать окно
    cmp  eax,2    ; нажата клавиша ?
    je	 key    ; если да - на key
    cmp  eax,3    ; нажата кнопка ?
    je	 button 	; если да - на button
CycleProcesEvents_ret:	  ret
;---  ОПРЕДЕЛЕНИЕ И ОТРИСОВКА ОКНА  ----------------------------------
DrawWindow:
mov EAX, 12
mov EBX, 1
INT0x40;

 mov EAX, 0
 mov EBX, (10*65536+10)  ;(10*65536+(257*3)+10) ; горизонтально
 add EBX,[WindowSizeX]
 mov ECX, (10*65536+27);(10*65536+(257*2)+27) ; вертикально
 add ECX,[WindowSizeY]
 mov EDX, 0x34000000;$33AABBCC
 mov  edi, titleE

INT0x40;

mov EAX, 12
mov EBX, 2
INT0x40;

jmp CycleProcesEvents         ; выходим из процедуры
;---------------------------------------------------------------------
key:          ; нажата клавиша на клавиатуре
call KeyProcess2
jmp CycleProcesEvents
;---------------------------------------------------------------------
  button:
  mov EAX, 17 ;    mcall 17            ; 17 - получить идентификатор нажатой кнопки
  INT0x40;
  ;GetEAX
    cmp   ah, 1 	; если НЕ нажата кнопка с номером 1,
    jne   CycleProcesEvents	    ;  вернуться
 .exit:
  Mov EAX, -1 ;   mcall -1            ; иначе конец программы
  INT0x40;
;---------------------------------------------------------------------
TimerAdrs rd 3
init_table_in_TimerAdrs:
call init_WindowSize
mov[TimerAdrs+(4*0)],EmulEngineTimer0
mov[TimerAdrs+(4*1)],EmulEngineTimer1
mov[TimerAdrs+(4*2)],EmulEngineTimer2
mov[TimerAdrs+(4*3)],EmulEngineTimer3
ret

init_WindowSize: ; установка окну соответ граф режима
mov eax,[GraphicsMode]; dd 2 ; графический режим  0- 256х256 ; 1 -512х512 2- 768х512
Cmp eax,0
jnz init_WindowSize_m1
mov[WindowSizeX],256
mov[WindowSizeY],256
ret
init_WindowSize_m1:
Cmp eax,1
jnz init_WindowSize_m2
mov[WindowSizeX],512
mov[WindowSizeY],512
ret
init_WindowSize_m2:
Cmp eax,2
jnz init_WindowSize_ret
mov[WindowSizeX],768
mov[WindowSizeY],512
init_WindowSize_ret: ret

INITmain: ; инициализация всего
mov dword [@FLagExit],0
call fillcharVideoDirty;
;call uVIDEOinit
call init_table_in_case_opcode
call KeyBoardInit
call init_table_in_TimerAdrs
call PlatoonTimer2
call TableGraphicsModeINIT
call TableKeyDopINIT
   ret
;---------------------------------------------------------------------
Timer1:
mov eax, 23 ; - номер функции
mov ebx, [TimerDelay];ebx = таймаут (в сотых долях секунды)
INT0x40;
ret
;---------------------------------------------------------------------
Timer2_result rd 1
Timer2:
mov eax,26
mov ebx,9
int 0x40
mov [Timer2_result],eax ;= число сотых долей секунды, прошедших с момента
ret

 PlatoonTimer2T rd 1
 PlatoonTimer2: ; взвод таймера (для блока комманд)
Call Timer2;
mov eax,[Timer2_result]
add eax,[TimerDelay]
mov [PlatoonTimer2T],eax
ret
;---------------------------------------------------------------------
Timer3:
mov eax, 26 ; Функция 26, подфункция 9 - получить значение счётчика времени.
mov ebx, 9 ;
mcall ;int 40 Возвращаемое значение:  * eax = число сотых долей секунды, прошедших с момента запуска системы
mov ebx, eax
shr ebx,1
inc ebx
shl ebx,1 ; ebx = время в сотых долях секунды
sub ebx,eax ;  eax = 5 - номер функции
mov eax,5 ; Функция 5 - пауза
mcall;int 40
ret

4

scancodeLV.asm

Код:
    ; запускасть ScanCodeKey
    ;Результат обработки в
    ScanCodeKey1 rd 1 ; "Чистый" код
    ScanCodeKey2 rd 1 ; обработаный код (-128 если больше 128)
    ScanCodeKeyUD rd 1 ; если 0 - отжата, если 1 -нажата
    ScanCodeKeyExt rd 1 ; 0- обычный код; 1 - доп ext (224); 2 - доп2 ext2 (225)
    ScanCodeKeyUnitedCode rd 1 ; "единый" код
  ScanCodeKey_int40_2dop:
     mov  eax,2
     mcall
     shr  eax,8       ; scancode
     and  eax,0xff
	ret

  ScanCodeKey_int40_2dop2:
Mov eax, 11 ;Функция 11 - проверить, есть ли событие, без ожидания. =======
INT 0x40
cmp  eax,2
jne ScanCodeKey_int40_2dop2_ret
 call	 ScanCodeKey_int40_2dop
 ScanCodeKey_int40_2dop2_ret:ret


ScanCodeKey:   ; START ScanCode
 call ScanCodeKey_int40_2dop

  cmp  eax,224 ; если доп код....
  jne  ScanCode_cmp_225;  если не равно нулю
  mov [ScanCodeKeyExt],1
  mov [ScanCodeKey1],0
;  call ScanCodeKey_int40_2dop; .... опросить клаву еще раз
;call ScanCodeKey_int40_2dop2
    JMP ScanCode_m2;ScanCode_m2

ScanCode_cmp_225:
   cmp	eax,225 ; если доп2 код....
    jne  ScanCode_m1;  если не равно нулю
  mov [ScanCodeKeyExt],2
  mov [ScanCodeKey1],0
;call ScanCodeKey_int40_2dop; .... опросить клаву еще раз
;call ScanCodeKey_int40_2dop2
  jmp ScanCode_m2

ScanCode_m1:
;mov [ScanCodeKeyExt],0
; САМА кодировка
ScanCode_m2:
;mov [ScanCodeKeyExt],0
mov[ScanCodeKey1], eax ; "Чистый" код
 ; Клавиша нажата DOWN
mov[ScanCodeKeyUD],1 ; если 0 - отжата, если 1 -нажата
    cmp  eax,128
    jb	 no_up
; Клавиша отжата секция UP
 mov[ScanCodeKeyUD],0 ; если 0 - отжата, если 1 -нажата

no_up:
    mov    ebx,eax
    and    ebx,0x7f
mov [ScanCodeKey2],ebx ; обработаный код (-128 если больше 128)

; "единый" код
mov eax,[ScanCodeKeyExt]
shl eax,8
add eax,ebx
mov[ScanCodeKeyUnitedCode],eax

ScanCodeKey_ret: ret

5

uDrawScreen.asm

Код:
;// Модуль вывода на экран
macro INT0x40 { int 0x40 }
;==============================
TableMy_col2INIT:
mov eax,[LVColBlack]
mov[TableMy_col2+(4*0)],eax
mov eax,[LVColLime]
mov[TableMy_col2+(4*1)],eax
mov eax,[LVColBlue]
mov[TableMy_col2+(4*2)],eax
mov eax,[LVColRed]
mov[TableMy_col2+(4*3)],eax
ret
;=================================
TableSupCol2INIT:
mov[TableSupCol2+(4*0)],SupCol2_ret
mov[TableSupCol2+(4*1)],SupCol2_m1
mov[TableSupCol2+(4*2)],SupCol2_m2
mov[TableSupCol2+(4*3)],SupCol2_m3
mov[TableSupCol2+(4*4)],SupCol2_m4
ret
;===============================
TableGraphicsModeINIT:
call TableMy_col2INIT
call TableSupCol2INIT
mov[TableGraphicsMode+(4*0)],PutPixel256_256
mov[TableGraphicsMode+(4*1)],PutPixel512_512
mov[TableGraphicsMode+(4*2)],PutPixel768_512

mov[TableDrawScreenPR+(4*0)],draw_screen256_256
mov[TableDrawScreenPR+(4*1)],draw_screen512_512
mov[TableDrawScreenPR+(4*2)],draw_screen768_512

ret

; ставит точку в массиве ImageData
; вывод пикселя на экран (в ImageData ) 
   PutPixel_x: rd 1
   PutPixel_y rd 1
   PutPixel_color rd 1
;===========================================   
PutPixel256_256:
    mov eax, [PutPixel_x]
    mov ebx ,[PutPixel_y]
    mov ecx ,[PutPixel_color]
    imul ebx, 256 * 4
     mov [ImageData+eax*4+ebx], ecx
    ret
;===========================================
PutPixel512_512:
    mov eax, [PutPixel_x]
    mov ebx ,[PutPixel_y]
    mov ecx ,[PutPixel_color]
    imul eax,2
    imul ebx, 512 * 4
    imul ebx,2 ; 
    mov [ImageData+eax*4+ebx], ecx; основная
    add eax,1
    mov [ImageData+eax*4+ebx], ecx; x+1
    ;============
    add ebx,512*4
    mov [ImageData+eax*4+ebx], ecx; 
    sub eax,1
    mov [ImageData+eax*4+ebx], ecx;
    ret
;===========================================
PutPixel768_512:
    mov eax, [PutPixel_x]
    mov ebx ,[PutPixel_y]
    mov ecx ,[PutPixel_color]
    imul eax,3
    imul ebx, 768 * 4
    imul ebx,2 ; 
    mov [ImageData+eax*4+ebx], ecx; основная
    add eax,1
    mov [ImageData+eax*4+ebx], ecx; x+1
    add eax,1
    mov [ImageData+eax*4+ebx], ecx; x+2
    ;============
    add ebx,768*4
    mov [ImageData+eax*4+ebx], ecx; 
    sub eax,1
    mov [ImageData+eax*4+ebx], ecx;
    sub eax,1
    mov [ImageData+eax*4+ebx], ecx;
    ret
;===========================================

; рисует массив ImageData на экран; вызывать с какой-нибудь периодичностью
draw_screen256_256:;DrawImageData:
    mov eax, 65
    mov ebx, ImageData
    mov ecx, 256 * 65536 + 256
    mov edx, 0;CanvasX * 65536 + CanvasY
    mov esi, 32
    xor ebp, ebp
    int 0x40
    ret
;=======================
draw_screen512_512:;DrawImageData:
    mov eax, 65
    mov ebx, ImageData
    mov ecx, 512 * 65536 + 512
    mov edx, 0;CanvasX * 65536 + CanvasY
    mov esi, 32
    xor ebp, ebp
    int 0x40
    ret
;=======================
draw_screen768_512:;DrawImageData:
    mov eax, 65
    mov ebx, ImageData
    mov ecx, 768 * 65536 + 512
    mov edx, 0;CanvasX * 65536 + CanvasY
    mov esi, 32
    xor ebp, ebp
    int 0x40
    ret
;=======================
PutPixel: ; процедура выбора режима экрана
  mov eax,[GraphicsMode]
 Call dword [eax*4+TableGraphicsMode] 
 ret
ret
;=======================
  col_index_port rd 1
  col_index_color rd 1
  col_index_result rd 1
col_index:
;917: port:=col_index_port; color:=col_index_color;
       mov eax,[col_index_port]
     mov ecx,[col_index_color]
;918: Result_:=LVColBlack;
     mov edx,[LVColBlack]
;919: if ((port and $40)<>0) then Result_:= (Result_ xor LVColBlue);
             test al,$40
             jz col_index_m1
       xor edx,[LVColBlue]           
;920: if ((port and $20)<>0) then Result_:= (Result_ xor LVColLime);
col_index_m1: test al,$20
             jz col_index_m2
     xor edx,[LVColLime]
;921: if ((port and $10)<>0) then Result_:= (Result_ xor LVColRed);
col_index_m2: test al,$10
             jz col_index_m3
     xor edx,[LVColRed]
;923: if color = LVColBlack then
col_index_m3:   cmp ecx,[LVColBlack]
             jnz col_index_m4
;925: if ((port and $08)=0) then
             test al,$08
             jnz col_index_m5
;926: begin Result_:= (Result_ xor LVColRed); end;
     xor edx,[LVColRed]
;927: if ((port and $04)=0) then
col_index_m5: test al,$04
             jnz col_index_ret
;928: begin Result_:= (Result_ xor LVColBlue); end;
     xor edx,[LVColBlue]
             jmp col_index_ret
;930: if color = LVColLime then begin Result_:= (Result_ xor LVColLime); end else
col_index_m4:   cmp ecx,[LVColLime]
             jnz col_index_m7
     xor edx,[LVColLime]
             jmp col_index_ret
;931: if color = LVColRed then begin Result_:= (Result_ xor LVColRed);
col_index_m7:  cmp ecx,[LVColRed]
             jnz col_index_m8
     xor edx,[LVColRed]
;uMainDA.pas.932: if ((port and $02)=0) then
             test al,$02
             jnz col_index_ret
;uMainDA.pas.933: begin Result_:= (Result_ xor LVColLime); end; end else
     xor edx,[LVColLime]
           jmp col_index_ret
;934: if color = LVColBlue then begin Result_:= (Result_ xor LVColBlue);
col_index_m8: cmp ecx,[LVColBlue]
              jnz col_index_ret
     xor edx,[LVColBlue]
;935: if ((port and $01)=0) then
             test al,$01
             jnz col_index_ret
;936: begin Result_:= (Result_ xor LVColRed); end; end;
     xor edx,[LVColRed]
;938: col_index_result:=result_;
col_index_ret:     mov [col_index_result],edx
;;//uMainDA.pas.940: end;
               ret    
;======================================================
  SupCol2_c1 rd 1
  SupCol2_b rd 1
  SupCol2_x rd 1
  SupCol2_Result rd 1
SupCol2:
;//1026: begin
               push ebx
               push esi
;             mov ebx,eax
;//1028: c1:=SupCol2_c1; b:=SupCol2_b; x:=SupCol2_x; pix:=0;
     mov ecx,[SupCol2_c1]
     mov edx,[SupCol2_b]
     mov esi,[SupCol2_x]
             xor eax,eax
;//1029: case x of (esi)
   jmp dword [esi*4+TableSupCol2]
;//1031: if (b and 128)=128 then pix:=pix+1;
SupCol2_m1:   mov esi,edx
           and esi,$00000080
        cmp esi,$00000080
             jnz SupCol2_m5
               inc eax
;//1032: if (b and 8)=8 then pix:=pix+2;
SupCol2_m5:  and edx,$08
           cmp edx,$08
             jnz SupCol2_ret2
           add eax,$02
             jmp SupCol2_ret2
;//1035: if (b and 64)=64 then pix:=pix+1;
SupCol2_m2:  mov esi,edx
          and esi,$40
           cmp esi,$40
             jnz SupCol2_m6
               inc eax
;//1036: if (b and 4)=4 then pix:=pix+2;
SupCol2_m6: and edx,$04
           cmp edx,$04
             jnz SupCol2_ret2
           add eax,$02
             jmp SupCol2_ret2
;//1039: if (b and 32)=32 then pix:=pix+1;
SupCol2_m3:   mov esi,edx
           and esi,$20
           cmp esi,$20
             jnz SupCol2_m7
               inc eax
;//1040: if (b and 2)=2 then pix:=pix+2;
SupCol2_m7: and edx,$02
           cmp edx,$02
             jnz SupCol2_ret2
           add eax,$02
             jmp SupCol2_ret2
;//1043: if (b and 16)=16 then pix:=pix+1;
SupCol2_m4:  mov esi,edx
           and esi,$10
           cmp esi,$10
             jnz SupCol2_m8
              inc eax
;//1044: if (b and 1)=1 then pix:=pix+2;
SupCol2_m8:  and edx,$01
           cmp edx,$01
             jnz SupCol2_ret2
           add eax,$02
;//1047: col_index_port:=c1;
SupCol2_ret2:
     mov [col_index_port],ecx
;//1048: My_Col_inp:=pix;My_Col2;
;//1049: col_index_color:=My_col_result;
mov eax,[eax*4+TableMy_col2]; ;       call My_col2
       mov [col_index_color],eax
;//1050: col_index;SupCol2_Result:=col_index_result;
       call col_index
       mov eax,[col_index_result]
       mov [SupCol2_Result],eax
;//1052: end;
SupCol2_ret:  pop esi
               pop ebx
               ret 
;================

 draw_screen2_i:rd 1 ; // Передача параметров на экран
draw_screen2:; //Рисуем с video на экран (Форму)
;               push ebx
;               push esi
;               push edi
;               mov ebx,eax
;//1139: vertX:= (draw_screen2_i mod 64)*4; gorY:=(draw_screen2_i div 64)*1;
       mov eax,[draw_screen2_i]
             and eax,$3f
             mov esi,eax
           shl esi,$02
       mov eax,[draw_screen2_i]
           shr eax,$06
             mov edi,eax
;//1140: Rports_a:=$C1;Rports;
;//1141: SupCol2_c1:=Rports_result;Rvideo_a:=draw_screen2_i;Rvideo;
   xor edx,edx
   mov dl,[portsM+$c1]
   mov [SupCol2_c1],edx
;//1142: SupCol2_b:=Rvideo_result; SupCol2_x:=1;SupCol2;
       mov edx,[draw_screen2_i]
       xor ebx,ebx
       mov bl,[videoM+edx]

       mov [SupCol2_b],ebx
       mov [SupCol2_x],$00000001
             mov eax,ebx
       call SupCol2
;//1143: PutPixel_x:=vertX;PutPixel_y:=gorY;PutPixel_color:= SupCol2_Result;PutPixel;{PutPixe2;}
     mov [PutPixel_x],esi
     mov [PutPixel_y],edi
       mov eax,[SupCol2_Result]
       mov [PutPixel_color],eax
             mov eax,ebx
       call PutPixel
;///1145: SupCol2_x:=2;SupCol2;
 mov [SupCol2_x],$00000002
             mov eax,ebx
       call SupCol2
;//1146: PutPixel_x:=vertX+1;PutPixel_y:=gorY;PutPixel_color:= SupCol2_Result;PutPixel;
           lea eax,[esi+$01]
       mov [PutPixel_x],eax
       mov [PutPixel_y],edi
       mov eax,[SupCol2_Result]
       mov [PutPixel_color],eax
             mov eax,ebx
       call PutPixel
;//1148: SupCol2_x:=3;SupCol2;
       mov [SupCol2_x],$00000003
             mov eax,ebx
       call SupCol2
;//1149: PutPixel_x:=vertX+2;PutPixel_y:=gorY;PutPixel_color:= SupCol2_Result;PutPixel;
           lea eax,[esi+$02]
       mov [PutPixel_x],eax
     mov [PutPixel_y],edi
       mov eax,[SupCol2_Result]
       mov [PutPixel_color],eax
             mov eax,ebx
       call PutPixel
;//1151: SupCol2_x:=4;SupCol2;
 mov [SupCol2_x],$00000004
             mov eax,ebx
       call SupCol2
;//1152: PutPixel_x:=vertX+3;PutPixel_y:=gorY;PutPixel_color:= SupCol2_Result;PutPixel;
           add esi,$03
     mov [PutPixel_x],esi
     mov [PutPixel_y],edi
       mov eax,[SupCol2_Result]
       mov [PutPixel_color],eax
             mov eax,ebx
       call PutPixel
;//uMainDA.pas.1153: end;
;               pop edi
;               pop esi
;               pop ebx
               ret
;============================
    draw_screen01_i rd 1
draw_screen01: ;{draw_screen:}
             push ebx
;//1227: draw_screen2_i:=draw_screen01_i; draw_screen2; // передача параметров для вывода на экран
       mov eax,[draw_screen01_i]
       mov [draw_screen2_i],eax
       call draw_screen2
;//1228: Rvideo_a:=draw_screen01_i;Rvideo;
       mov edx,[draw_screen01_i]
       xor ebx,ebx
       mov bl,[videoM+edx]
;//1229: WVideoDirty_a:=draw_screen01_i; WVideoDirty_b:=Rvideo_Result;WVideoDirty;
       mov eax,[draw_screen01_i]
mov [eax+VideoDirtyM],bl ;       call WVideoDirty
              pop ebx
               ret
;==============               
draw_screen:
;//1261: begin;///1263: for i:=0 to $3fff do begin
             xor ebx,ebx
;//1265: Rvideo_a:=i;Rvideo;
draw_screen_m2:
;//1266: RVideoDirty_a:=i;RVideoDirty;
   xor ecx,ecx
mov cl,[VideoDirtyM+ebx]
       xor eax,eax
       mov al,[videoM+ebx]
;//1267: if Rvideo_Result<>RVideoDirty_Result then //сравниваем значения , а есть ли изменения
     cmp eax,ecx;[RVideoDirty_result]
             jz draw_screen_m1
;//1269: draw_screen01_i:=i; draw_screen01;
     mov [draw_screen01_i],ebx
       call draw_screen01
;//1271: end;
draw_screen_m1: inc ebx
;//1263: for i:=0 to $3fff do begin
     cmp ebx,$00004000
             jnz draw_screen_m2
;//1272: draw_screen1; // реальный вывод на экран
   mov eax,[GraphicsMode]
 Call dword [eax*4+TableDrawScreenPR]
              ret
;=======================================

6

ui8080.asm Part1

Код:
;// модуль процессора (движка)
m01m:;begin{ tmp2:=tmp2+1} asm
     inc dword [tmp2]
     ret
;end; end;

m04m:; Begin {rgA:=(tmp2 and $FF);} asm
       mov eax,[tmp2]
       and eax,$000000ff
     mov edx, rgA
             mov [edx],eax
               ret
;end;end;

 m06m:; Begin {rgA:=tmp2;} asm
 mov eax, rgA
 mov edx,[tmp2]
 mov [eax],edx
       ret
;end;  end;

m07m:;Begin {Rflags_a:=tmp2;Rflags; rgF:=(Rflags_result or (rgF and fC));} asm
;            mov eax,[tmp2]
;         mov [Rflags_a],eax
;       call Rflags
    mov edx,[tmp2]
   xor ebx,ebx
   mov bl,[flagsM+edx]
  ;mov [Rflags_result],ebx
  
       mov eax, rgF
         mov eax,[eax]
         mov edx,  fC
             and eax,[edx]
     or eax,ebx ;[Rflags_result]
     mov edx, rgF
            mov [edx],eax
               ret
;end;end;

m08m:;Begin //Rflags_a:=(tmp2 and $FF);Rflags; rgF:=Rflags_result;

;asm
       mov eax,[tmp2]
       and eax,$000000ff
;       mov [Rflags_a],eax
;          call Rflags
    xor edx,edx
   mov dl,[flagsM+eax]
        mov eax, rgF
;       mov edx,[Rflags_result]
             mov [eax],edx
               ret
;end; end;

m09m:;begin //Rflags_a:=(tmp2);Rflags; rgF:=Rflags_result;
;asm
       mov eax,[tmp2]
  
   xor edx,edx
   mov dl,[flagsM+eax]
       mov eax, rgF
             mov [eax],edx
              ret
;end; end;

m10m:;begin //Rflags_a:=(0);Rflags; rgF:=Rflags_result;
;//!!!!!!!!!!!!!! Не проверена
;asm
      xor edx,edx
   mov dl,[flagsM]
       mov [rgF],edx
              ret
;end;end;

m11m:;begin //Rflags_a:=(rgA);Rflags; rgF:=(Rflags_result or (rgF and fA));
;asm
       mov eax,[rgA]
   xor ebx,ebx
   mov bl,[flagsM+eax]
             mov eax,[rgF]
             and eax,[fA]
     or eax,ebx
         mov [rgF],eax
               ret
;end; end;

m12m:;begin //rgF:=(rgF or fA);
;asm
       mov eax, fA
             mov eax,[eax]
     mov edx, rgF
             or [edx],eax
               ret
;end;end;

m13m:;
;begin //rgF:=(rgF or fC);
;asm
       mov eax, fC
           mov eax,[eax]
     mov edx, rgF
             or [edx],eax
              ret
;end;end;

жmD8m:;begin // rgPC:=(rgPC and $FFFF)
;asm
;       mov eax, [rgPC]
;      and eax,$0000ffff
;            ret
;end;end;

m14m:;begin //rgPC:=rgPC+1; mD8m;
;asm
inc dword [rgPC]
;call mD8m
ret
;end;end;


m15m:;begin //rgPC:=rgPC+2; mD8m;
;asm
  add dword [rgPC],$02
;       call mD8m
              ret
 ;end; end;

m02m:;begin //rgPC:=rgPC+3; mD8m;
;asm
add dword [rgPC],$03
;call mD8m
ret
;end; end;

m16m:;begin {clock:=clock+4;}
;asm
add dword [clock],$04
;call mD8m
              ret
;end;end;

m17m:;begin {clock:=clock+7;}
;asm
add dword [clock],7
;call mD8m
              ret
;end;end;

m18m:;begin {clock:=clock+5;}
;asm
add dword [clock],5
;call mD8m
              ret
;end;end;

m19m:;begin {clock:=clock+10;}
;asm
add dword [clock],10
;call mD8m
              ret
;end;end;

m20m:;begin {clock:=clock+11;}
;asm
add dword [clock],11
;call mD8m
              ret
;end;end;

m21m:;begin {clock:=clock+13;}
;asm
add dword [clock],13
;call mD8m
              ret
;end;end;

m22m:;begin {clock:=clock+16;}
;asm
add dword [clock],16
;call mD8m
              ret
;end;end;

m23m:;begin {clock:=clock+17;}
;asm
add dword [clock],17
;call mD8m
              ret
;end;end;

m24m:;label m24m_m1; begin {if ((rgF and fC)<>0) then m01m else tmp2:=tmp2+0;}
;asm
       mov eax,[rgF]
     and eax,[fC]
             jz  m24m_m1
       call m01m
m24m_m1:    ret
;//m24m_m1:   add dword ptr [tmp2],$00
;//              ret
;end;end;

m25m:;begin //m18m; m14m;end;
;   asm
      call m18m
      call m14m
        ret
 ;end; end;

m27m:;begin //m16m; m14m; end;
; asm
      call m16m
      call m14m
        ret
 ;end; end;

m26m:;begin //m11m; m27m;end;
 ;asm
      call m11m
      call m27m
          ret
 ;;end; end;

m28m:; begin //do_read_addr:=(rgPC+2);do_read; m28m_Result:=do_read_Result;
;asm
         mov eax,[rgPC]
           add eax,$02
       mov [do_read_addr],eax
       call do_read
           mov eax, [do_read_result]
           mov edx, m28m_Result
           mov [edx],eax
              ret
;end;end;

m29m:; begin //do_read_addr:=(rgPC+1);do_read; m29m_Result:=do_read_Result;
;asm
          mov eax,[rgPC]
               inc eax
         mov [do_read_addr],eax
       call do_read
       mov eax,[do_read_result]
       mov [m29m_Result],eax
               ret
;end;end;

m30m:; begin //do_read2_a_lo:=rgL; do_read2_a_hi:=rgH; do_read2; m30m_Result:=do_read2_result;
;asm
       mov eax,[rgL]
       mov [do_read2_a_lo],eax
       mov eax,[rgH]
       mov [do_read2_a_hi],eax
       call do_read2
       mov eax,[do_read2_result]
       mov [m30m_Result],eax
               ret
;end;end;
m03m:;begin //m19m; m02m; end;
 ;asm
      call m19m
      call m02m
        ret
 ;end; end;
 m31m:;begin// m17m; m14m; end;
 ;asm
      call m17m
      call m14m
        ret
 ;end; end;
 
m32m:;label m32m_ret;begin //if (tmp2>$FF) then m13m;
;asm
        cmp [tmp2],$000000ff
        jbe  m32m_ret
        call m13m
m32m_ret:        ret
;end; end;

m33m:;begin //m17m; m15m; end;
 ;asm
      call m17m
      call m15m
        ret
 ;end; end;

m34m:;begin //m19m; m14m; end;
 ;asm
      call m19m
      call m14m
        ret
 ;end; end;

m05m:;Begin //m32m; m04m; m27m; end;
 ;asm
      call m32m
      call m04m
      call m27m
        ret
 ;end; end;

m35m:;Begin //m06m; m27m; end;
; asm
      call m06m
      call m27m
        ret
 ;end; end;

m36m:; label m36m_ret; Begin //if (((tmp2 xor rgA xor m36m_a) and $10)<>0) then begin m12m;
;asm
       mov eax,[tmp2]
     xor eax,[rgA]
     xor eax,[m36m_a]
             test al,$10
             jz  m36m_ret
       call m12m
m36m_ret:         ret
 ;end; end;
 
m37m:; label m37m_m1, m37m_m2; begin
 ;//if ((rgF and fC)<>0) then tmp3:=1 else tmp3:=0;
 ;// tmp2:=(rgA-m37m_a-tmp3) and $FF;
;asm
      mov eax,[rgF]
     and eax,[fC]
             jz  m37m_m1
      mov [tmp3],$00000001
             jmp m37m_m2
m37m_m1:   xor eax,eax
       mov [tmp3],eax
m37m_m2:  mov eax,[rgA]
     sub eax,[m37m_a]
     sub eax,[tmp3]
       and eax,$000000ff
       mov [tmp2],eax
    ret
;end;end;

m38m:; begin //m30m;m38m_Result:=m30m_Result; m31m;
;asm
       call m30m
       mov eax,[m30m_Result]
       mov [m38m_Result],eax
       call m31m
            ret
;end;end;

m39m:; begin //m29m;m39m_Result:=m29m_Result; m33m;
;asm
       call m29m
       mov eax,[m29m_Result]
       mov [m39m_Result],eax
       call m33m
               ret
;end; end;

m40m:; label m40m_m1; begin
;//tmp2:=(rgA-m40m_a) and $FF; m09m; if (rgA<m40m_a) then begin m13m; end; m36m_a:=m40m_a;m36m; m35m; end;
;asm
       mov eax,[rgA]
      sub eax,[m40m_a]
       and eax,$000000ff
       mov [tmp2],eax
       call m09m
       mov eax,[rgA]
      cmp eax,[m40m_a]
           jnb m40m_m1
       call m13m
m40m_m1:  mov eax,[m40m_a]
       mov [m36m_a],eax
       call m36m
       call m35m
               ret
;end;end;

 m41m:; label m41m_m1; begin //m37m_a:=m41m_a;m37m; m09m; if (rgA<(m41m_a+tmp3)) then begin m13m; end;
;//m36m_a:=m41m_a;m36m; m35m;end;
;asm
       mov eax,[m41m_a]
       mov [m37m_a],eax
       call m37m
       call m09m
        mov eax,[m41m_a]
       add eax,[tmp3]
       cmp eax,[rgA]
        jbe m41m_m1
       call m13m
m41m_m1:       mov eax,[m41m_a]
       mov [m36m_a],eax
       call m36m
       call m35m
             ret
;end;end;

m42m:; label m42m_ret; begin //if (((tmp2 xor m42m_a) and $10)<>0) then begin m12m; end; end;
;asm
       mov eax,[tmp2]
       xor eax,[m42m_a]
         test al,$10
             jz m42m_ret
       call m12m
m42m_ret:        ret
;end;end;

m43m:; begin//  m07m; m42m_a:=m43m_a;m42m; e
;asm
        call m07m
       mov eax,[m43m_a]
       mov [m42m_a],eax
       call m42m
               ret
;end;end;

m44m:; begin //do_write2_a_lo:=rgL;do_write2_a_hi:=rgH;do_write2_bt:=m44m_a; do_write2; end;
;asm
       mov eax,[rgL]
       mov [do_write2_a_lo],eax
       mov eax,[rgH]
       mov [do_write2_a_hi],eax
       mov eax,[m44m_a]
       mov [do_write2_bt],eax
       call do_write2
               ret
;end;end;

m46m:; begin //m28m;m29m;m46m_Result:=m29m_Result+(m28m_Result shl 8);
;asm
       call m28m
       call m29m
       mov eax,[m28m_Result]
           shl eax,$08
     add eax,[m29m_Result]
       mov [m46m_Result],eax
              ret
;end;end;

m45m:; begin //m46m;rgPC:=m46m_Result; end;
;asm
       call m46m
       mov eax,[m46m_Result]
       mov [rgPC],eax
               ret
;end;end;

m47m:; begin //m29m;tmp1:=m29m_Result; end;
;asm
         call m29m
       mov eax,[m29m_Result]
       mov [tmp1],eax
               ret
;end;end;

m48m:; begin// m46m; tmp1:=m46m_Result; end;
;asm
       call m46m
       mov eax,[m46m_Result]
       mov [tmp1],eax
               ret
;end;end;

m49m:; begin //do_read_addr:=(rgSP);do_read; rgPC:=do_read_Result;end;
;asm
       mov eax,[rgSP]
       mov [do_read_addr],eax
       call do_read
       mov eax,[do_read_result]
       mov [rgPC],eax
              ret
;end;end;

m50m:; begin //rgSP:=(rgSP-2) and $FFFF;end;
;asm
       mov eax,[rgSP]
           sub eax,$02
       and eax,$0000ffff
       mov [rgSP],eax
              ret
;end;end;

m51m:; begin //rgPC:=tmp1; m23m; end;
;asm
       mov eax,[tmp1]
       mov [rgPC],eax
      call m23m
               ret
;end;end;

m52m:; begin //m48m; m50m; m02m; end;
 ;asm
      call m48m
      call m50m
      call m02m
        ret
 ;end; end;

m53m:; label m53m_m1; Begin //if ((rgF and fS_)<>0) then
;//m53m_Result:=1 else m53m_Result:=0 end;
;asm
       mov eax,[rgF]
      and eax,[fS_]
             jz  m53m_m1
 mov [m53m_Result],$00000001
               ret
m53m_m1:     xor eax,eax
       mov [m53m_Result],eax
              ret
;end;end;

m54m:; label m54m_m1; Begin //if ((rgF and fS_)=0) then m54m_Result:=1 else m54m_Result:=0; end;
;asm
      mov eax,[rgF]
     and eax,[fS_]
             jnz m54m_m1
 mov [m54m_Result],$00000001
          ret
m54m_m1:             xor eax,eax
       mov [m54m_Result],eax
               ret
;end;end;

m55m:; begin //m55m_Result:=(rgPC shr 8) and $FF; end;
;asm
       mov eax,[rgPC]
           shr eax,$08
       and eax,$000000ff
       mov [m55m_Result],eax
               ret
;end;end;

m56m:; begin //do_write_addr:=rgSP; do_write_bt:=(rgPC and $FF);do_write; end;
;asm
       mov eax,[rgSP]
       mov [do_write_addr],eax
       mov eax,[rgPC]
       and eax,$000000ff
       mov [do_write_bt],eax
       call do_write
               ret
;end;end;

m57m:; label m57m_m1;Begin //if ((rgF and fC)<>0) then m57m_Result:=1 else m57m_Result:=0; end;
;asm
       mov eax,[rgF]
     and eax,[fC]
             jz m57m_m1
 mov [m57m_Result],$00000001
               ret 
m57m_m1:             xor eax,eax
       mov [m57m_Result],eax
               ret 
;end;end;

m58m:; label m58m_m1; Begin //if ((rgF and fP)=0) then m58m_Result:=1 else m58m_Result:=0; end;
 ;asm
        mov eax,[rgF]
     and eax,[fP]
            jnz  m58m_m1
 mov [m58m_Result],$00000001
               ret
 m58m_m1:       xor eax,eax
       mov [m58m_Result],eax
               ret
; end; end;

 m59m:; label m59m_m1;begin //if ((rgF and fC)=0) then m59m_Result:=1 else m59m_Result:=0; end;
; asm
        mov eax,[rgF]
     and eax,[fC]
          jnz  m59m_m1
 mov [m59m_Result],$00000001
               ret
m59m_m1:     xor eax,eax
       mov [m59m_Result],eax
               ret
; end; end;

m60m:; label m60m_m1;Begin //if ((rgF and fZ)=0) then m60m_Result:=1 else m60m_Result:=0; end;
 ;asm
        mov eax,[rgF]
     and eax,[fZ]
             jnz m60m_m1
 mov [m60m_Result],$00000001
              ret
  m60m_m1:       xor eax,eax
       mov [m60m_Result],eax
               ret
; end; end;

m61m:; begin //rgA:=rgA and m61m_a; end;
 ;asm
     mov eax,[m61m_a]
     and [rgA],eax
           ret
; end; end;

m62m:; label m62m_m1; begin //if (rgA<m62m_a) then begin m13m; end; m36m_a:=m62m_a;m36m; m27m; end;
 ;asm
       mov eax,[rgA]
     cmp eax,[m62m_a]
             jnb m62m_m1
       call m13m
 m62m_m1:       mov eax,[m62m_a]
      mov [m36m_a],eax
       call m36m
       call m27m
               ret
; end; end;

m63m:; begin //tmp2:=(rgA-m63m_a) and $FF; m09m; m62m_a:=m63m_a; m62m;end;
;asm
       mov eax,[rgA]
     sub eax,[m63m_a]
       and eax,$000000ff
       mov [tmp2],eax
       call m09m
       mov eax,[m63m_a]
       mov [m62m_a],eax
       call m62m
              ret
;end;end;

m64m:; begin //rgA:=(rgA or m64m_a);end;
 ;asm
        mov eax,[m64m_a]
     or [rgA],eax
               ret
 ;end; end;

m65m:; begin //rgF:=rgF or fC; end;
;asm
       mov eax,[fC]
      or [rgF],eax
           ret
;end; end;

m66m:; begin //rgSP:=(rgSP+2) and $FFFF;end;
;asm
       mov eax,[rgSP]
           add eax,$02
       and eax,$0000ffff
       mov [rgSP],eax
               ret
;end;end;

m67m:; begin //rgA:=(rgA xor m67m_a);end;
;asm
       mov eax,[m67m_a]
     xor [rgA],eax
              ret
;end;end;

m68m:; begin //m52m; m56m; do_write_addr:=(rgSP+1); m55m; do_write_bt:=m55m_Result;do_write; m51m; end;
;asm
       call m52m
       call m56m
       mov eax,[rgSP]
               inc eax
       mov [do_write_addr],eax
       call m55m
       mov eax,[m55m_Result]
       mov [do_write_bt],eax
       call do_write
       call m51m
               ret
;end;end;

m69m:; begin //rgF:=(rgF and (not fC)); end;
;asm
       mov eax,[fC]
           not eax
     and [rgF],eax
               ret
;end;end;

mD7m:; begin //m08m; m36m_a:=mD7m_a;m36m; end;
;asm
       call m08m
       mov eax,[mD7m_a]
       mov [m36m_a],eax
       call m36m
           ret
;end;end;

m70m:; begin //tmp2:=rgA+m70m_a; mD7m_a:=m70m_a;mD7m; m05m; end;
;asm
      mov eax,[rgA]
      add eax,[m70m_a]
       mov [tmp2],eax
       mov eax,[m70m_a]
       mov [mD7m_a],eax
       call mD7m
       call m05m
          ret
;end;end;

m73m:;  begin // tmp2:=rgA+m73m_a; m24m; mD7m_a:=m73m_a; mD7m;end;
; asm
      mov eax,[rgA]
       add eax,[m73m_a]
       mov [tmp2],eax
       call m24m
       mov eax,[m73m_a]
       mov [mD7m_a],eax
       call mD7m
           ret
; end;end;

m71m:; begin //m73m_a:=m71m_a; m73m; m05m; end;
;asm
       mov eax,[m71m_a]
       mov [m73m_a],eax
       call m73m
       call m05m
           ret
;end;end;

m74m:; begin //m30m;tmp1:=m30m_Result; end;
;asm
       call m30m
       mov eax,[m30m_Result]
       mov [tmp1],eax
               ret
;end;end;

m75m:; begin //tmp2:=(rgA-tmp1) and $FF; end;
;asm
       mov eax,[rgA]
     sub eax,[tmp1]
       and eax,$000000ff
      mov [tmp2],eax
          ret

;end;end;

m76m:; label m76m_m1; begin //if (rgA<tmp1) then begin m65m; end; end;
;asm
       mov eax,[rgA]
     cmp eax,[tmp1]
             jnb  m76m_m1
       call m65m
m76m_m1:    ret
;end;end;

m77m:; begin //m45m; m19m; end;
 ;asm
      call m45m
      call m19m
        ret
; end; end;

m78m:;//begin m20m; m02m; end;
;asm
      call m20m
      call m02m
        ret
;end; end;

m79m:; label m79m_m1; Begin //if ((rgF and fP)<>0) then m79m_Result:=1 else m79m_Result:=0; end;
;asm
       mov eax,[rgF]
     and eax,[fP]
             jz m79m_m1
 mov [m79m_Result],$00000001
               ret
m79m_m1:     xor eax,eax
       mov [m79m_Result],eax
               ret
;end;end;

m80m:; begin //do_read_addr:=(rgSP+1);do_read;rgPC:=rgPC+ do_read_Result shl 8; end;
;asm
       mov eax,[rgSP]
               inc eax
       mov [do_read_addr],eax
       call do_read
       mov eax,[do_read_result]
           shl eax,$08
     add [rgPC],eax
               ret
;end;end;

m82m:; begin //m49m; m80m; m66m; m20m; end;
 ;asm
      call m49m
      call m80m
      call m66m
      call m20m
        ret
 ;end; end;

 m84m:; begin //rgB:=m84m_a; m25m; end;
;asm
 mov [rgB],eax
 call m25m
 ret
;end;end;

m85m:; begin //tmp2:=(m85m_a and $FF); end;
;asm
       and eax,$000000ff
       mov [tmp2],eax
               ret
;end;end;

m86m:; begin //rgC:=m86m_a; m25m; end;
;asm
       mov [rgC],eax
       call m25m
               ret
;end;end;

m87m:; begin //rgD:=m87m_a; m25m; end;
;asm
       mov [rgD],eax
       call m25m
               ret
;end;end;

m88m:; begin //rgE:=m88m_a; m25m; end;
;asm
       mov [rgE],eax
       call m25m
               ret
;end;end;

m89m:; begin //rgH:=m89m_a; m25m; end;
;asm
       mov [rgH],eax
       call m25m
               ret
;end;end;

m90m:; begin //rgL:=m90m_a; m25m; end;
;asm
       mov [rgL],eax
       call m25m
               ret
;end;end;

m91m:; begin //m44m_a:=m91m_a; m44m; m31m; end;
;asm
       mov eax,[m91m_a]
       mov [m44m_a],eax
       call m44m
       call m31m
               ret
;end;end;

m92m:; begin //rgA:=m92m_a; m25m; end;
;asm
       mov [rgA],eax
       call m25m
               ret
;end;end;

m99m:; Begin //m06m; m25m; end;
 ;asm
      call m06m
      call m25m
        ret
 ;end; end;

mA1m:; label mA1m_m1; Begin //if ((rgF and fZ)<>0) then mA1m_Result:=1 else mA1m_Result:=0 end;
;asm
       mov eax,[rgF]
     and eax,[fZ]
             jz  mA1m_m1
   mov [mA1m_Result],$00000001
               ret
mA1m_m1:          xor edx,edx
           mov [mA1m_Result],edx
               ret
;end;end;

mA2m:; Begin //m32m; m04m; end;
; asm
      call m32m
      call m04m
        ret
 ;end; end;

mA3m:; Begin //mA2m; m31m; end;
 ;asm
      call mA2m
      call m31m
        ret
 ;end; end;

mA4m:; Begin //m11m; m31m; end;
 ;asm
      call m11m
      call m31m
        ret
 ;end; end;

mA5m:; begin //m61m_a:=mA5m_a; m61m; m26m; end;
;asm
mov [m61m_a],eax
  call m61m
       call m26m
               ret
;end;end;

mA6m:; begin //m67m_a:=mA6m_a; m67m; m26m; end;
;asm
       mov eax,[mA6m_a]
       mov [m67m_a],eax
       call m67m
       call m26m
          ret
;end; end;


mA7m:; Begin //m50m; m14m; m56m; do_write_addr:=(rgSP+1); m55m; do_write_bt:=m55m_Result;do_write; end;
;asm
       call m50m
       call m14m
       call m56m
       mov eax,[rgSP]
               inc eax
       mov [do_write_addr],eax
       call m55m
       mov eax,[m55m_Result]
       mov [do_write_bt],eax
       call do_write
             ret
;end;end;

mA8m:; Begin //do_write_addr:=(rgSP+1); m55m; do_write_bt:=m55m_Result;do_write; end;
;asm
       mov eax,[rgSP]
               inc eax
       mov [do_write_addr],eax
       call m55m
       mov eax,[m55m_Result]
       mov [do_write_bt],eax
   
       call do_write
             ret
;end;end;

mA9m:; Begin //m56m; mA8m; end;
 ;asm
      call m56m
      call mA8m
        ret
 ;;end; end;

mB1m:; Begin //mA9m; m51m; end;
 ;asm
      call mA9m
      call m51m
        ret
 ;end; end;
 
mB2m:; Begin //m20m; m14m; end;
 ;asm
      call m20m
      call m14m
        ret
 ;end; end;


mB3m:; Begin //m11m; m33m; end;
 ;asm
      call m11m
      call m33m
        ret
 ;end; end;

mB4m:; Begin
;//do_write_addr:=(rgSP);
;//do_write_bt:=mB4m_a1;do_write;
;// do_write_addr:=(rgSP+1); do_write_bt:=mB4m_a2;do_write; end;
;asm
       mov eax,[rgSP]
       mov [do_write_addr],eax
    mov eax,[mB4m_a1]
     mov [do_write_bt],eax
       call do_write
      mov eax,[rgSP]
              inc eax
       mov [do_write_addr],eax
   mov eax,[mB4m_a2]
       mov [do_write_bt],eax
       call do_write
               ret
 ;end;end;

mB5m:; Begin //m43m_a:=rgB; m43m; rgB:=tmp2; m25m;end;
;asm
       mov eax,[rgB]
       mov [m43m_a],eax
      call m43m
       mov eax,[tmp2]
       mov [rgB],eax
       call m25m
               ret
;end;end;


mB6m:; Begin //do_write_addr:=mB6m_a; do_write_bt:=rgH;do_write; end;
;asm
           mov eax,[mB6m_a]
       mov [do_write_addr],eax
       mov eax,[rgH]
       mov [do_write_bt],eax
       call do_write
               ret
;end;end;

 mB7m:; Begin
 ;//do_write_addr:=mB7m_a; do_write_bt:=rgL;do_write; end;
;asm
        mov eax,[mB7m_a]
       mov [do_write_addr],eax
       mov eax,[rgL]
       mov [do_write_bt],eax
       call do_write
              ret
;end;end;

 mB8m:; begin //do_read_addr:=(rgSP);do_read; mB8m_Result:=do_read_Result; end;
;asm
       mov eax,[rgSP]
      mov [do_read_addr],eax
       call do_read
       mov eax,[do_read_result]
       mov [mB8m_Result],eax
               ret
;end;end;

mB9m:; begin //do_read_addr:=(rgSP+1);do_read;mB9m_Result:=do_read_Result; end;
;asm
       mov eax,[rgSP]
       inc eax
       mov [do_read_addr],eax
       call do_read
       mov eax,[do_read_result]
       mov [mB9m_Result],eax
               ret
;end;end;

mC1m:; begin //m43m_a:=rgH; m43m; rgH:=tmp2; m25m; end;
;asm
       mov eax,[rgH]
       mov [m43m_a],eax
       call m43m
      mov eax,[tmp2]
       mov [rgH],eax
       call m25m
               ret
;end;end;

mC2m:; begin //m19m; m15m; end;
 ;asm
      call m19m
      call m15m
        ret
; end; end;

mC3m:; begin //m43m_a:=rgC; m43m; rgC:=tmp2; m25m; end;
;asm
      mov eax,[rgC]
       mov [m43m_a],eax
       call m43m
       mov eax,[tmp2]
       mov [rgC],eax
       call m25m
               ret
;end;end;

mC4m:; begin //m43m_a:=rgD; m43m; rgD:=tmp2; m25m; end;
;asm
       mov eax,[rgD]
       mov [m43m_a],eax
      call m43m
       mov eax,[tmp2]
       mov [rgD],eax
       call m25m
              ret
;end;end;

mC5m:; begin //m43m_a:=rgE; m43m; rgE:=tmp2; m25m; end;
;asm
       mov eax,[rgE]
       mov [m43m_a],eax
       call m43m
       mov eax,[tmp2]
       mov [rgE],eax
       call m25m
               ret
;end;end;

mC6m:; begin //m22m; m02m; end;
; asm
      call m22m
      call m02m
        ret
; end; end;

mC7m:; begin //m43m_a:=rgL; m43m; rgL:=tmp2; m25m; end;
;asm
       mov eax,[rgL]
       mov [m43m_a],eax
       call m43m
       mov eax,[tmp2]
       mov [rgL],eax
       call m25m
              ret
;end;end;

mC8m:; begin //m43m_a:=tmp1; m43m; m44m_a:=tmp2; m44m; m34m; end;
;asm
     mov eax,[tmp1]
     mov [m43m_a],eax
       call m43m
       mov eax,[tmp2]
      mov [m44m_a],eax
       call m44m
       call m34m
               ret
;end;end;

mC9m:; begin //m43m_a:=rgA; m43m; m99m;
;asm
       mov eax,[rgA]
       mov [m43m_a],eax
       call m43m
       call m99m
           ret
;end;end;

mD1m:; begin //m36m_a:=tmp1; m36m; m06m; m31m; end;
;asm
       mov eax,[tmp1]
       mov [m36m_a],eax
       call m36m
       call m06m
       call m31m
               ret
;end;end;

mD2m:; begin //m74m; m75m; m09m; end;
; asm
      call m74m
      call m75m
      call m09m
        ret
; end; end;

mD3m:; begin //m66m; m34m; end;
; asm
      call m66m
      call m34m
        ret
; end; end;

mD4m:; begin //m04m; m33m; end;
; asm
      call m04m
      call m33m
        ret
; end; end;

mD5m:; begin //m06m; m33m; end;
 ;asm
      call m06m
      call m33m
        ret
; end; end;

mD6m:; begin //m47m; m75m; m09m; m76m; m36m_a:=tmp1; m36m;end;
;asm
         call m47m
       call m75m
       call m09m
       call m76m
       mov eax,[tmp1]
     mov [m36m_a],eax
       call m36m
               ret
;end;end;
;//Procedure mD7m; - в верху
;//Procedure mD8m; - в верху
mD9m:; begin //m85m; mB5m; end;
 ;asm
      call m85m
      call mB5m
        ret
; end; end;

mE1m:; begin //m85m; mC1m; end;
 ;asm
      call m85m
      call mC1m
        ret
; end; end;

mE2m:; begin //m85m; mC7m; end;
 ;asm
      call m85m
      call mC7m
        ret
; end; end;

mE3m:; begin //m85m; mC8m; end;
 ;asm
      call m85m
      call mC8m
        ret
; end; end;

mE4m:; begin //m85m; mC9m; end;
 ;asm
      call m85m
      call mC9m
        ret
; end; end;
;====================
;====================
;====================
;====================
;====================
C00: ;Begin asm
      call m27m
         ret
; end; end;
C01: ;begin //m28m;rgB:=m28m_Result; m29m;rgC:=m29m_Result; m03m; end;
;asm
       call m28m
       mov eax,[m28m_Result]
       mov [rgB],eax
       call m29m
       mov eax,[m29m_Result]
       mov [rgC],eax
       call m03m
           ret
;end;end;

C02:; begin //do_write2_a_lo:=rgC;do_write2_a_hi:=rgB;do_write2_bt:=rgA; do_write2; m31m; end;
;asm
       mov eax,[rgC]
       mov [do_write2_a_lo],eax
       mov eax,[rgB]
       mov [do_write2_a_hi],eax
       mov eax,[rgA]
      mov [do_write2_bt],eax
             mov eax,ebx
       call do_write2
       call m31m
            ret
;end;end;

C03: ; begin //rgC:=rgC+1; if (rgC>$FF) then begin rgC:=0; rgB:=rgB+1;
;// if (rgB>$FF) then begin rgB:=0; end; end; m25m; end;
;asm
   inc dword [rgC]
 cmp [rgC],$000000ff
             jbe c03_m1
             xor eax,eax
       mov [rgC],eax
     inc dword [rgB]

 cmp [rgB],$000000ff
             jbe c03_m1
             xor eax,eax
       mov [rgB],eax
c03_m1:     call m25m
             ret
;end;end;

C04: ;begin //m85m_a:=(rgB+1); mD9m; end;
;asm
       mov eax,[rgB]
               inc eax
       mov [m85m_a],eax
       call mD9m
                ret

;end;end;

C05: ;begin //m85m_a:=(rgB-1); mD9m; end;
;asm
       mov eax,[rgB]
               dec eax
       mov [m85m_a],eax
       call m85m
       call mB5m
               ret
;end;end;

C06: ;/begin //m39m; rgB:=m39m_Result; end;
;asm
       call m39m
       mov eax,[m39m_Result]
       mov [rgB],eax
               ret
;end;end;

C07:; begin //rgA:=rgA SHL 1; if (rgA>$FF) then begin rgA:=rgA or 1; m65m; rgA:= rgA and $FF; end
;// else begin m69m; end; m27m; end;
;'asm
     shl [rgA],1
 cmp [rgA],$000000ff
             jbe c07_m1
   or dword [rgA],$01
       call m65m
 and [rgA],$000000ff
             jmp c07_m2
c07_m1: call m69m
c07_m2:      call m27m
             ret
;end;end;

C08:;Begin asm
      call m27m
        ret
; end; end;

C09: ;begin //rgL:=rgL+rgC; rgH:=rgH+rgB; if (rgL>$FF) then
;// begin inc(rgH); rgL:=(rgL and $FF); end;
;// if (rgH>$FF) then begin rgH:=(rgH and $FF); m13m;
;// end else begin m69m; end; m34m; end;
;asm
;//uMainDA.pas.2295: $09: begin rgL:=rgL+rgC; rgH:=rgH+rgB; if (rgL>$FF) then
       mov eax,[rgC]
     add [rgL],eax
       mov eax,[rgB]
     add [rgH],eax
 cmp [rgL],$000000ff
             jbe  c09_m1
;//uMainDA.pas.2296: begin inc(rgH); rgL:=(rgL and $FF); end;
     inc dword [rgH]
 and [rgL],$000000ff
;//uMainDA.pas.2297: if (rgH>$FF) then begin rgH:=(rgH and $FF); m13m;
c09_m1: cmp [rgH],$000000ff
             jbe c09_m2
 and [rgH],$000000ff
       call m13m
             jmp c09_m3
;//uMainDA.pas.2298: end else begin m69m; end; m34m; end;
c09_m2:   call m69m
c09_m3:   call m34m
             ret
;end;end;



C0A: ;begin //do_read2_a_lo:=rgC; do_read2_a_hi:=rgB; do_read2; rgA:=do_read2_result; m31m;
;asm
       mov eax,[rgC]
       mov [do_read2_a_lo],eax
       mov eax,[rgB]
       mov [do_read2_a_hi],eax
             mov eax,ebx
       call do_read2
       mov eax,[do_read2_result]
       mov [rgA],eax
       call m31m
               ret
;end;end;

C0B:; begin //rgC:=rgC-1; if (rgC>=$FFFFFF00) then begin rgC:=(rgC and $FF); rgB:=rgB-1;
;  //if (rgB>=$FFFFFF00) then begin rgB:=(rgB and $FF); end; end; m25m; end;
;asm
     dec dword [rgC]
 cmp [rgC],$ffffff00
             jb C0B_m1
 and [rgC],$000000ff
     dec dword [rgB]
 cmp [rgB],$ffffff00
             jb C0B_m1
 and [rgB],$000000ff
C0B_m1:   call m25m
                ret
;end;end;


C0C: ;begin //m85m_a:=(rgC+1); m85m; mC3m; end;
;asm
       mov eax,[rgC]
               inc eax
       mov [m85m_a],eax
       call m85m
       call mC3m
               ret
;end;end;

C0D: ;begin //m85m_a:=(rgC-1); m85m; mC3m; end;
;asm
       mov eax,[rgC]
               dec eax
       mov [m85m_a],eax
       call m85m
       call mC3m
            ret
;end;end;

C0E: ;begin //m39m; rgC:=m39m_Result; end;
;asm
      call m39m
       mov eax,[m39m_Result]
       mov [rgC],eax
               ret
;end;end;

C0F: ;begin //tmp1:=(rgA and 1); rgA:=(rgA shr 1); if (tmp1<>0) then
;// begin rgA:=(rgA or $80); m13m; end else
;// begin rgF:=(rgF and ( not fC)); end; m27m; end;
;asm
       mov eax,[rgA]
           and eax,$01
       mov [tmp1],eax
     shr [rgA],1
   cmp dword [tmp1],$00
             jz C0F_m1
 or [rgA],$00000080
       call m13m
             jmp C0F_m2
C0F_m1:    mov eax,[fC]
             not eax
     and [rgF],eax
C0F_m2: call m27m
               ret
;end;end;

C10: ;Begin asm
      call m27m
         ret
; end; end;

C11: ;begin //m28m;rgD:=m28m_Result; m29m;rgE:=m29m_Result; m03m; end;
;asm
       call m28m
       mov eax,[m28m_Result]
       mov [rgD],eax
       call m29m
       mov eax,[m29m_Result]
       mov [rgE],eax
       call m03m
           ret
;end;end;

C12: ;begin //do_write2_a_lo:=rgE;do_write2_a_hi:=rgD;do_write2_bt:=rgA; do_write2; m31m; end;
;asm
       mov eax,[rgE]
       mov [do_write2_a_lo],eax
       mov eax,[rgD]
       mov [do_write2_a_hi],eax
       mov eax,[rgA]
       mov [do_write2_bt],eax
             mov eax,ebx
       call do_write2
        call m31m
               ret
;end;end;

C13: ;begin //rgE:=rgE+1; if (rgE>$FF) then begin rgE:=0; rgD:=rgD+1;
;// if (rgD>$FF) then begin rgD:=0; end; end; m25m; end;
;asm
     inc dword [rgE]
 cmp [rgE],$000000ff
             jbe C13_m2
             xor eax,eax
       mov [rgE],eax
   inc dword [rgD]
 cmp [rgD],$000000ff
             jbe C13_m2
            xor eax,eax
       mov [rgD],eax
C13_m2:   call m25m
               ret
;end;end;

C14: ;begin //m85m_a:=(rgD+1); m85m; mC4m; end;
;asm
       mov eax,[rgD]
          inc eax
       mov [m85m_a],eax
       call m85m
       call mC4m
            ret
;end;end;

C15: ;begin //m85m_a:=(rgD-1); m85m; mC4m; end;
;asm
       mov eax,[rgD]
         dec eax
       mov [m85m_a],eax
       call m85m
       call mC4m
           ret
;end;end;

C16: ;begin //m39m; rgD:=m39m_Result; end;
;asm
       call m39m
       mov eax,[m39m_Result]
       mov [rgD],eax
             ret
;end;end;

C17: ;begin //rgA:=(rgA shl 1); m57m; if m57m_Result<>0 then begin rgA:=(rgA or 1); end;
;//if (rgA>$FF) then begin m13m; rgA:=(rgA and $FF); end else begin m69m; end; m27m; end;
;asm
     shl [rgA],1
       call m57m
   cmp dword [m57m_Result],$00
             jz  C17_m1
   or dword [rgA],$01
C17_m1: cmp [rgA],$000000ff
             jbe C17_m2
       call m13m
 and [rgA],$000000ff
             jmp C17_m3
C17_m2:    call m69m
C17_m3:     call m27m
               ret
;end;end;

C18:;//m27m;
;Begin asm
      call m27m
        ret
;end; end;

C19: ;begin //rgL:=(rgL + rgE); rgH:=(rgH + rgD); if (rgL>$FF) then
;// begin inc(rgH); rgL:=(rgL and $FF); end;
;// if (rgH>$FF) then begin rgH:=(rgH and $FF); m13m;
;// end else begin rgF:=(rgF and not (fC)); end; m34m; end;
;asm
      mov eax,[rgE]
     add [rgL],eax
       mov eax,[rgD]
     add [rgH],eax
 cmp [rgL],$000000ff
             jbe C19_m1

     inc dword [rgH]
 and [rgL],$000000ff

C19_m1: cmp [rgH],$000000ff
             jbe C19_m2
 and [rgH],$000000ff
       call m13m
             jmp C19_m3

C19_m2:   mov eax,[fC]
             not eax
     and [rgF],eax
C19_m3:       call m34m
               ret
;end;end;

C1A: ;begin //do_read2_a_lo:=rgE; do_read2_a_hi:=rgD; do_read2; rgA:=do_read2_result; m31m;
;asm
       mov eax,[rgE]
       mov [do_read2_a_lo],eax
       mov eax,[rgD]
       mov [do_read2_a_hi],eax
             mov eax,ebx
       call do_read2
       mov eax,[do_read2_result]
       mov [rgA],eax
       call m31m
               ret
;end; end;

C1B: ;begin //rgE:=rgE-1; if (rgE>=$FFFFFF00) then begin rgE:=(rgE and $FF); rgD:=rgD-1;
;// if (rgD>=$FFFFFF00) then begin rgD:=(rgD and $FF); end; end; m25m; end;
;asm
     dec dword [rgE]
 cmp [rgE],$ffffff00
             jb C1B_m1
 and [rgE],$000000ff
     dec dword [rgD]

 cmp [rgD],$ffffff00
             jb C1B_m1
 and [rgD],$000000ff
C1B_m1:  call m25m
               ret
;end; end;

C1C: ;begin //m85m_a:=(rgE+1); m85m; mC5m; end;
;asm
       mov eax,[rgE]
            inc eax
       mov [m85m_a],eax
       call m85m
       call mC5m
             ret
;end; end;

C1D: ;begin //m85m_a:=(rgE-1); m85m; mC5m; end;
;asm
       mov eax,[rgE]
               dec eax
       mov [m85m_a],eax
       call m85m
       call mC5m
               ret
;end; end;

C1E: ;begin //m39m; rgE:=m39m_Result; end;
;asm
       call m39m
       mov eax,[m39m_Result]
       mov [rgE],eax
               ret

;end; end;

C1F: ;begin //tmp1:=(rgA and 1); rgA:=(rgA SHR 1); m57m;   //if m57m_Result<>0 then begin rgA:=(rgA or $80); end;
;//if (tmp1<>0) then begin m13m; end// else begin rgF:=(rgF and not(fC)); end;//  m27m; end;
;asm
     mov eax,[rgA]
           and eax,$01
      mov [tmp1],eax
     shr [rgA],1
      call m57m
   cmp dword [m57m_Result],$00
         jz C1F_m1
 or [rgA],$00000080
C1F_m1:   cmp dword [tmp1],$00
             jz C1F_m2
     call m13m
            jmp C1F_m3
C1F_m2:   mov eax,[fC]
             not eax
     and [rgF],eax
C1F_m3:      call m27m
              ret
;end;end;

C20:;//m27m;
;Begin asm
      call m27m
         ret
; end; end;

C21: ;begin //m28m;rgH:=m28m_Result; m29m;rgL:=m29m_Result; m03m; end;
;asm
       call m28m
       mov eax,[m28m_Result]
       mov [rgH],eax
       call m29m
       mov eax,[m29m_Result]
       mov [rgL],eax
       call m03m
               ret

;end;end;

C22: ;begin //m48m; mB7m_a:=(tmp1); mB7m; mB6m_a:=(tmp1+1); mB6m; mC6m; end;
;asm
       call m48m
       mov eax,[tmp1]
       mov [mB7m_a],eax
       call mB7m
       mov eax,[tmp1]
              inc eax
       mov [mB6m_a],eax
       call mB6m
       call mC6m
            ret
;end;end;

C23: ;begin //rgL:=rgL+1; if (rgL>$FF) then begin rgL:=0; rgH:=rgH+1;
;//if (rgH>$FF) then begin rgH:=0; end; end;
;//m25m; end;
;asm
     inc dword [rgL]
 cmp [rgL],$000000ff
             jbe C23_m1
             xor eax,eax
       mov [rgL],eax
     inc dword [rgH]
 cmp [rgH],$000000ff
         jbe C23_m1
        xor eax,eax
       mov [rgH],eax
C23_m1:  call m25m
             ret
;end;end;

C24: ;begin //m85m_a:=(rgH+1); mE1m; end;
;asm
       mov eax,[rgH]
               inc eax
       mov [m85m_a],eax
       call mE1m
              ret
;end;end;

C25: ;begin //m85m_a:=(rgH-1); mE1m; end;
;asm
       mov eax,[rgH]
          dec eax
       mov [m85m_a],eax
       call mE1m
           ret
;end;end;

C26: ;begin //m39m; rgH:=m39m_Result; end;
;asm
       call m39m
       mov eax,[m39m_Result]
       mov [rgH],eax
           ret
;end;end;

C27: ;begin //tmp1:=0; if (((rgF and fC)<>0) or (rgA>$99)) then
;// begin tmp1:=(tmp1 or $60); end;
;// if (((rgF and fA)<>0) or ((rgA and $0F)>$09)) then begin tmp1:=(tmp1 or $06); end;
;// tmp2:=rgA+tmp1; m08m; m36m_a:=tmp1; m36m; mA2m; m27m; end;
;asm
             xor eax,eax
       mov [tmp1],eax
       mov eax,[rgF]
     and eax,[fC]
             jnz C27_m1
     cmp [rgA],$00000099
             jbe C27_m2
C27_m1:  or dword [tmp1],$60
C27_m2:       mov eax,[rgF]
     and eax,[fA]
             jnz C27_m3
       mov eax,[rgA]
           and eax,$0f
           cmp eax,$09
           jbe  C27_m3
 or dword [tmp1],$06
C27_m3:  mov eax,[rgA]
     add eax,[tmp1]
       mov [tmp2],eax
       call m08m
       mov eax,[tmp1]
       mov [m36m_a],eax
       call m36m
       call mA2m
       call m27m
            ret
;end;end;

C28:;//m27m;
;Begin asm
      call m27m
         ret
; end; end;

C29: ;begin //rgL:=rgL + rgL; rgH:=rgH + rgH; if (rgL>$FF) then
;//begin inc(rgH); rgL:=(rgL and $FF); end;
;//if (rgH>$FF) then begin rgH:=(rgH and $FF); m13m; end else begin m69m; end;
;//m34m; end;
;asm
       mov eax,[rgL]
     add [rgL],eax
       mov eax,[rgH]
     add [rgH],eax
 cmp [rgL],$000000ff
             jbe  C29_m1

     inc dword [rgH]
 and [rgL],$000000ff
C29_m1: cmp [rgH],$000000ff
             jbe C29_m2

 and [rgH],$000000ff
       call m13m
          jmp C29_m3

C29_m2:    call m69m
C29_m3:    call m34m
               ret
;end;end;

C2A: ;begin //m48m; do_read_addr:=(tmp1);do_read;rgL:=do_read_Result;
;//do_read_addr:=(tmp1+1);do_read;rgH:=do_read_Result; mC6m; end;
;asm
       call m48m
       mov eax,[tmp1]
       mov [do_read_addr],eax
             mov eax,ebx
       call do_read
       mov eax,[do_read_result]
      mov [rgL],eax
       mov eax,[tmp1]
               inc eax
       mov [do_read_addr],eax
             mov eax,ebx
       call do_read
       mov eax,[do_read_result]
       mov [rgH],eax
       call mC6m
              ret
;end;end;

C2B: ;begin //rgL:=rgL-1; if (rgL>=$FFFFFF00) then begin rgL:=(rgL and $FF) ; rgH:=rgH-1;
;// if (rgH>=$FFFFFF00) then begin rgH:=(rgH and $FF); end; end; m25m; end;
;asm
     dec dword [rgL]
 cmp [rgL],$ffffff00
             jb C2B_m1

 and [rgL],$000000ff
     dec dword [rgH]
 cmp [rgH],$ffffff00
             jb C2B_m1

 and [rgH],$000000ff
C2B_m1:     call m25m
             ret
;end;end;

C2C: ;begin //m85m_a:=(rgL+1); mE2m; end;
;asm
       mov eax,[rgL]
               inc eax
       mov [m85m_a],eax
       call mE2m
             ret
;end;end;

C2D: ;begin //m85m_a:=(rgL-1); mE2m; end;
;asm
       mov eax,[rgL]
               dec eax
       mov [m85m_a],eax
       call mE2m
               ret
;end;end;

C2E: ;begin //m39m; rgL:=m39m_Result; end;
;asm
       call m39m
       mov eax,[m39m_Result]
       mov [rgL],eax
            ret
;end;end;

C2F: ;begin //rgA:=(rgA xor $FF); m27m; end;
;asm
     xor [rgA],$000000ff
       call m27m
         ret
;end;end;

C30:;m27m;
;Begin asm
      call m27m
        ret
;;end; end;

C31: ;begin //m28m;m29m;rgSP:=(m28m_Result shl 8)+m29m_Result; m03m; end;
;asm
       call m28m
       call m29m
       mov eax,[m28m_Result]
           shl eax,$08
     add eax,[m29m_Result]
       mov [rgSP],eax
       call m03m
           ret
;end;end;

C32: ;begin //m29m;do_write2_a_lo:=m29m_Result;m28m;do_write2_a_hi:=m28m_Result;do_write2_bt:=rgA; do_write2; m21m; m02m; end;
;asm
       call m29m
       mov eax,[m29m_Result]
       mov [do_write2_a_lo],eax
       call m28m
       mov eax,[m28m_Result]
       mov [do_write2_a_hi],eax
       mov eax,[rgA]
       mov [do_write2_bt],eax
             mov eax,ebx
       call do_write2
       call m21m
       call m02m
               ret
;end;end;

C33: ;begin //if (rgSP=$FFFF) then begin rgSP:=0; end else begin inc(rgSP); end; m25m; end;
;asm
 cmp [rgSP],$0000ffff
             jnz C33_m1
             xor eax,eax
       mov [rgSP],eax
             jmp C33_m2
C33_m1: inc dword [rgSP]
C33_m2: call m25m
               ret
;end;end;

C34: ;begin //m74m; m85m_a:=(tmp1+1); mE3m; end;
;asm
       call m74m
       mov eax,[tmp1]
               inc eax
       mov [m85m_a],eax
       call mE3m
              ret
;end;end;

C35: ;begin //m74m; m85m_a:=(tmp1-1); mE3m; end;
;asm
       call m74m
       mov eax,[tmp1]
         dec eax
       mov [m85m_a],eax
       call m85m
       call mC8m
            ret
;end;end;

C36: ;begin //m29m;m44m_a:=m29m_Result; m44m; mC2m; end;
;asm
       call m29m
       mov eax,[m29m_Result]
       mov [m44m_a],eax
       call m44m
       call mC2m
          ret
;end;end;

C37: ;//begin m13m; m27m; end;
;Begin asm
      call m13m
      call m27m
         ret
 ;end; end;

C38:;///m27m;
;Begin asm
      call m27m
        ret
 ;end; end;

C39: ;begin //rgL:=(rgL + (rgSP and $FF)); rgH:=(rgH + ((rgSP shr 8) and $FF));
;// if (rgL>$FF) then begin inc(rgH); rgL:=(rgL and $FF); end;
;// if (rgH>$FF) then begin rgH:=(rgH and $FF); m13m; end else begin m69m; end;
;//m34m; end;
;asm
       mov eax,[rgSP]
       and eax,$000000ff
     add [rgL],eax
       mov eax,[rgSP]
           shr eax,$08
       and eax,$000000ff
     add [rgH],eax
  cmp [rgL],$000000ff
            jbe  C39_m1
     inc dword [rgH]
 and [rgL],$000000ff
 C39_m1: cmp [rgH],$000000ff
             jbe C39_m2
  and [rgH],$000000ff
       call m13m
             jmp C39_m3
 C39_m2:  call m69m
C39_m3:       call m34m
               ret
;end;end;

C3A: ;begin //m29m;do_read2_a_lo:=m29m_Result; m28m;do_read2_a_hi:=m28m_Result; do_read2; rgA:=do_read2_result;
;// m21m; m02m; end;
;asm
       call m29m
       mov eax,[m29m_Result]
       mov [do_read2_a_lo],eax
       call m28m
       mov eax,[m28m_Result]
       mov [do_read2_a_hi],eax
             mov eax,ebx
       call do_read2
       mov eax,[do_read2_result]
       mov [rgA],eax
       call m21m
       call m02m
               ret
;end;end;

C3B: ;begin //if (rgSP<>0) then begin rgSP:=rgSP-1; end else begin rgSP:=$FFFF; end;
;// m25m; end;
;asm
   cmp dword [rgSP],$00
             jz C3B_m1
     dec dword [rgSP]
             jmp C3B_m2
C3B_m1: mov [rgSP],$0000ffff
C3B_m2:    call m25m
               ret
;end;end;

C3C: ;begin //m85m_a:=(rgA+1); mE4m; end;
;asm
       mov eax,[rgA]
               inc eax
       mov [m85m_a],eax
       call mE4m
             ret
;end;end;

C3D: ;begin //m85m_a:=(rgA-1); mE4m; end;
;asm
       mov eax,[rgA]
               dec eax
       mov [m85m_a],eax
       call mE4m
               ret
;end;end;

C3E: ;begin //m39m; rgA:=m39m_Result; end;
;asm
       call m39m
       mov eax,[m39m_Result]
       mov [rgA],eax
              ret
;end;end;

C3F: ;begin //rgF:=rgF xor fC; m27m; end;
;asm
       mov eax,[fC]
     xor [rgF],eax
       call m27m
               ret
;end;end;

C40:;//m25m;
;Begin asm
      call m25m
        ret
 ;end; end;

;{B}
C41: ;begin //m84m_a:=rgC; m84m; end;
;asm
       mov eax,[rgC]
       mov [m84m_a],eax
       call m84m
              ret
;end;end;

C42: ;begin //m84m_a:=rgD;m84m; end;
;asm
       mov eax,[rgD]
       mov [m84m_a],eax
       call m84m
               ret
;end;end;

C43: ;begin //m84m_a:=rgE; m84m; end;
;asm
       mov eax,[rgE]
       mov [m84m_a],eax
       call m84m
               ret
;end;end;

C44: ;begin //m84m_a:=rgH; m84m; end;
;asm
       mov eax,[rgH]
       mov [m84m_a],eax
       call m84m
               ret
;end;end;

C45: ;begin //m84m_a:=rgL; m84m; end;
;asm
       mov eax,[rgL]
       mov [m84m_a],eax
       call m84m
               ret
;end;end;

C46: ;begin //m38m; rgB:=m38m_Result; end;
;asm
       call m38m
       mov eax,[m38m_Result]
       mov [rgB],eax
               ret
;end;end;

7

ui8080.asm Part2

Код:
C47: ;begin //m84m_a:=rgA;m84m; end;
;asm
       mov eax,[rgA]
       mov [m84m_a],eax
       call m84m
               ret
;end;end;

;{C}
C48: ;begin //m86m_a:=(rgB); m86m; end;
;asm
       mov eax,[rgB]
       mov [m86m_a],eax
       call m86m
              ret
;end;end;

C49: ;//m25m;
;Begin asm
      call m25m
        ret
 ;end; end;

C4A: ;begin //m86m_a:=(rgD); m86m; end;
;asm
       mov eax,[rgD]
       mov [m86m_a],eax
       call m86m
              ret
;end;end;

C4B: ;begin //m86m_a:=(rgE); m86m; end;
;asm
       mov eax,[rgE]
       mov [m86m_a],eax
       call m86m
              ret
;end;end;

C4C: ;begin //m86m_a:=(rgH); m86m; end;
;asm
       mov eax,[rgH]
       mov [m86m_a],eax
       call m86m
              ret
;end;end;

C4D: ;begin //m86m_a:=(rgL); m86m; end;
;asm
       mov eax,[rgL]
       mov [m86m_a],eax
       call m86m
              ret
;end;end;

C4E: ;begin// m38m;rgC:=m38m_Result; end;
;asm
       call m38m
       mov eax,[m38m_Result]
       mov [rgC],eax
               ret
;end;end;

C4F: ;begin //m86m_a:=(rgA); m86m; end;
;asm
       mov eax,[rgA]
       mov [m86m_a],eax
       call m86m
              ret
;end;end;

;{d}
C50: ;begin //m87m_a:=(rgB); m87m; end;
;asm
       mov eax,[rgB]
       mov [m87m_a],eax
       call m87m
               ret
;end;end;

C51: ;begin //m87m_a:=(rgC); m87m; end;
;asm
       mov eax,[rgC]
       mov [m87m_a],eax
       call m87m
               ret
;end;end;

C52: ;//m25m;
;Begin asm
      call m25m
        ret
; end; end;

C53: ;begin //m87m_a:=(rgE); m87m; end;
;asm
       mov eax,[rgE]
       mov [m87m_a],eax
       call m87m
               ret
;end;end;

C54: ;begin //m87m_a:=(rgH); m87m; end;
;asm
       mov eax,[rgH]
       mov [m87m_a],eax
       call m87m
               ret
;end;end;

C55: ;begin //m87m_a:=(rgL); m87m; end;
;asm
       mov eax,[rgL]
       mov [m87m_a],eax
       call m87m
               ret
;end;end;

C56: ;begin //m38m;rgD:=m38m_Result; end;
;asm
       call m38m
       mov eax,[m38m_Result]
       mov [rgD],eax
               ret
;end;end;

C57: ;begin //m87m_a:=(rgA);m87m; end;
;asm
       mov eax,[rgA]
       mov [m87m_a],eax
       call m87m
               ret
;end;end;
;{E}
C58: ;begin //m88m_a:=(rgB); m88m; end;
;asm
       mov eax,[rgB]
       mov [m88m_a],eax
       call m88m
               ret
;end;end;

C59: ;begin //m88m_a:=(rgC); m88m; end;
;asm
       mov eax,[rgC]
       mov [m88m_a],eax
       call m88m
               ret
;end;end;

C5A: ;begin //m88m_a:=(rgD); m88m; end;
;asm
       mov eax,[rgD]
       mov [m88m_a],eax
       call m88m
               ret
;end;end;

C5B: ;//m25m;
;Begin asm
      call m25m
        ret
 ;end; end;

C5C: ;begin //m88m_a:=(rgH);m88m; end;
;asm
       mov eax,[rgH]
       mov [m88m_a],eax
       call m88m
               ret
;end;end;

C5D: ;begin //m88m_a:=(rgL); m88m; end;
;asm
       mov eax,[rgL]
       mov [m88m_a],eax
       call m88m
               ret
;end;end;

C5E: ;begin //m38m;rgE:=m38m_Result; end;
;asm
       call m38m
       mov eax,[m38m_Result]
       mov [rgE],eax
               ret
;end;end;

C5F: ;begin //m88m_a:=(rgA);m88m; end;
;asm
       mov eax,[rgA]
       mov [m88m_a],eax
       call m88m
               ret
;end;end;
;{H}
C60: ;begin //m89m_a:=(rgB); m89m; end;
;asm
       mov eax,[rgB]
       mov [m89m_a],eax
      call m89m
               ret
;end;end;

C61: ;begin //m89m_a:=(rgC); m89m; end;
;asm
       mov eax,[rgC]
       mov [m89m_a],eax
       call m89m
               ret
;end;end;

C62: ;begin //m89m_a:=(rgD); m89m; end;
;asm
       mov eax,[rgD]
       mov [m89m_a],eax
       call m89m
               ret
;end;end;

C63: ;begin //m89m_a:=(rgE); m89m; end;
;asm
       mov eax,[rgE]
       mov [m89m_a],eax
       call m89m
           ret
;end;end;

C64:;//m25m;
;Begin asm
      call m25m
        ret
; end; end;

C65: ;begin //m89m_a:=(rgL); m89m; end;
;asm
       mov eax,[rgL]
       mov [m89m_a],eax
       call m89m
               ret
;end;end;

C66: ;begin //m38m; rgH:=m38m_Result; end;
;asm
       call m38m
       mov eax,[m38m_Result]
       mov [rgH],eax
               ret
;end;end;

C67: ;begin //m89m_a:=(rgA); m89m; end;
;asm
       mov eax,[rgA]
       mov [m89m_a],eax
       call m89m
               ret
;end;end;

;{L}
C68: ;begin //m90m_a:=(rgB); m90m; end;
;asm
      mov eax,[rgB]
       mov [m90m_a],eax
       call m90m
               ret
;end;end;

C69: ;begin //m90m_a:=(rgC); m90m; end;
;asm
       mov eax,[rgC]
       mov [m90m_a],eax
       call m90m
               ret
;end;end;

C6A: ;begin //m90m_a:=(rgD); m90m; end;
;asm
       mov eax,[rgD]
      mov [m90m_a],eax
       call m90m
            ret
;end;end;

C6B: ;begin //m90m_a:=(rgE); m90m; end;
;asm
       mov eax,[rgE]
       mov [m90m_a],eax
       call m90m
               ret
;end;end;

C6C: ;begin //m90m_a:=(rgH); m90m; end;
;asm
       mov eax,[rgH]
       mov [m90m_a],eax
       call m90m
               ret
;end;end;

C6D:;//m25m;
;Begin asm
      call m25m
         ret
; end; end;

C6E: ;begin //m38m; rgL:=m38m_Result;end;
;asm
      call m38m
       mov eax,[m38m_Result]
       mov [rgL],eax
            ret
;end;end;


C6F: ;begin //m90m_a:=(rgA); m90m; end;
;asm
       mov eax,[rgA]
       mov [m90m_a],eax
       call m90m
          ret
;end;end;

;{M}
C70: ;begin //m91m_a:=(rgB); m91m; end;
;asm
       mov eax,[rgB]
       mov [m91m_a],eax
       call m91m
           ret
;end;end;

C71: ;begin //m91m_a:=(rgC); m91m; end;
;asm
       mov eax,[rgC]
       mov [m91m_a],eax
       call m91m
          ret
;end;end;

C72: ;begin //m91m_a:=(rgD); m91m; end;
;asm
       mov eax,[rgD]
       mov [m91m_a],eax
       call m91m
          ret
;end;end;

C73: ;begin //m91m_a:=(rgE); m91m; end;
;asm
       mov eax,[rgE]
       mov [m91m_a],eax
       call m91m
          ret
;end;end;

C74: ;begin //m91m_a:=(rgH); m91m; end;
;asm
       mov eax,[rgH]
       mov [m91m_a],eax
       call m91m
          ret
;end;end;

C75: ;begin //m91m_a:=(rgL); m91m; end;
;asm
       mov eax,[rgL]
       mov [m91m_a],eax
       call m91m
          ret
;end;end;

C76: ;//m27m;
;Begin asm
      call m27m
        ret
; end; end;

C77: ;begin //m91m_a:=(rgA); m91m; end;
;asm
       mov eax,[rgA]
       mov [m91m_a],eax
       call m91m
               ret
;end;end;

C78: ;begin //m92m_a:=(rgB); m92m; end;
;asm
       mov eax,[rgB]
       mov [m92m_a],eax
       call m92m
               ret
;end;end;

C79: ;begin //m92m_a:=(rgC); m92m; end;
;asm
       mov eax,[rgC]
       mov [m92m_a],eax
       call m92m
               ret
;end;end;

C7A: ;begin //m92m_a:=(rgD); m92m; end;
;asm
       mov eax,[rgD]
       mov [m92m_a],eax
       call m92m
               ret
;end;end;

C7B: ;begin //m92m_a:=(rgE); m92m; end;
;asm
       mov eax,[rgE]
       mov [m92m_a],eax
       call m92m
               ret
;end;end;

C7C: ;begin //m92m_a:=(rgH); m92m; end;
;asm
       mov eax,[rgH]
       mov [m92m_a],eax
       call m92m
               ret
;end;end;

C7D: ;begin //m92m_a:=(rgL); m92m; end;
;asm
       mov eax,[rgL]
       mov [m92m_a],eax
       call m92m
               ret
;end;end;

C7E: ;begin //m38m;rgA:=m38m_Result; end;
;asm
       call m38m
       mov eax,[m38m_Result]
       mov [rgA],eax
               ret
;end;end;

C7F: ;//m25m;
;Begin asm
      call m25m
        ret
; end; end;

C80: ;begin// tmp2:=rgA+rgB; m08m; m36m_a:=rgB; m36m; m32m; rgA:=(tmp2 and $FF); m27m; end;
;asm
       mov eax,[rgA]
     add eax,[rgB]
       mov [tmp2],eax
       call m08m
       mov eax,[rgB]
       mov [m36m_a],eax
       call m36m
       call m32m
       mov eax,[tmp2]
       and eax,$000000ff
       mov [rgA],eax
       call m27m
               ret
;end;end;

C81: ;begin //m70m_a:=rgC; m70m; end;
;asm
       mov eax,[rgC]
       mov [m70m_a],eax
       call m70m
               ret
;end;end;

C82:;$82:begin //m70m_a:=rgD; m70m; end;
;asm
       mov eax,[rgD]
       mov [m70m_a],eax
       call m70m
               ret
;end;end;

C83: ;begin //m70m_a:=rgE; m70m; end;
;asm
       mov eax,[rgE]
       mov [m70m_a],eax
       call m70m
               ret
;end;end;

C84: ;begin //m70m_a:=rgH; m70m; end;
;asm
       mov eax,[rgH]
       mov [m70m_a],eax
       call m70m
               ret
;end;end;

C85: ;begin //m70m_a:=rgL; m70m; end;
;asm
       mov eax,[rgL]
       mov [m70m_a],eax
       call m70m
               ret
;end;end;

C86: ;begin //m74m; tmp2:=rgA+tmp1; m08m; m36m_a:=tmp1; m36m; mA3m; end;
;asm
       call m74m
       mov eax,[rgA]
     add eax,[tmp1]
       mov [tmp2],eax
       call m08m
       mov eax,[tmp1]
       mov [m36m_a],eax
       call m36m
       call mA3m
              ret
;end; end;

C87: ;begin //m70m_a:=rgA; m70m; end;
;asm
       mov eax,[rgA]
       mov [m70m_a],eax
       call m70m
              ret
;end; end;

C88: ;begin //m71m_a:=rgB; m71m; end;
;asm
       mov eax,[rgB]
       mov [m71m_a],eax
       call m71m
             ret
;end; end;

C89: ;begin //m71m_a:=rgC; m71m; end;
;asm
       mov eax,[rgC]
      mov [m71m_a],eax
       call m71m
               ret
;end; end;

C8A: ;begin //m71m_a:=rgD; m71m; end;
;asm
       mov eax,[rgD]
       mov [m71m_a],eax
       call m71m
               ret
 ;end; end;

C8B: ;begin //m71m_a:=rgE; m71m; end;
;asm
       mov eax,[rgE]
       mov [m71m_a],eax
       call m71m
               ret
;end; end;

C8C: ;begin //m73m_a:=rgH; m73m; if (tmp2>$FF) then
;//begin m65m; end; m04m; m27m; end;
;asm
       mov eax,[rgH]
       mov [m73m_a],eax
       call m73m
 cmp [tmp2],$000000ff
             jbe C8C_m1
       call m65m
C8C_m1:      call m04m
       call m27m
               ret
;end; end;

C8D: ;begin //m71m_a:=rgL; m71m; end;
;asm
       mov eax,[rgL]
       mov [m71m_a],eax
       call m71m
               ret
;end; end;

C8E: ;begin //m74m; m73m_a:=tmp1; m73m; mA3m; end;
;asm
       call m74m
       mov eax,[tmp1]
       mov [m73m_a],eax
       call m73m
       call mA3m
               ret
;end; end;

C8F: ;begin //m71m_a:=rgA; m71m; end;
;asm
       mov eax,[rgA]
       mov [m71m_a],eax
       call m71m
               ret
;end; end;

C90: ;begin //m40m_a:=rgB;m40m; end;
;asm
       mov eax,[rgB]
       mov [m40m_a],eax
       call m40m
             ret
;end; end;

C91: ;begin //m40m_a:=rgC; m40m; end;
;asm
       mov eax,[rgC]
       mov [m40m_a],eax
       call m40m
              ret
;end; end;

C92: ;begin //m40m_a:=rgD;m40m; end;
;asm
       mov eax,[rgD]
       mov [m40m_a],eax
       call m40m
               ret
;end;end;

C93: ;begin //m40m_a:=rgE; m40m; end;
;asm
       mov eax,[rgE]
       mov [m40m_a],eax
       call m40m
               ret
;end;end;

C94: ;begin //m40m_a:=rgH; m40m; end;
;asm
       mov eax,[rgH]
       mov [m40m_a],eax
       call m40m
               ret
;end; end;

C95: ;begin //m85m_a:=(rgA-rgL); m85m; m09m; if (rgA<rgL) then begin m65m; end; m36m_a:=rgL; m36m; m35m; end;
;asm
       mov eax,[rgA]
     sub eax,[rgL]
       mov [m85m_a],eax
       call m85m
       call m09m
       mov eax,[rgA]
     cmp eax,[rgL]
             jnb C95_m1
       call m65m
C95_m1:       mov eax,[rgL]
       mov [m36m_a],eax
       call m36m
       call m35m
               ret
;end; end;

C96: ;begin //mD2m; if (rgA<tmp1) then begin m13m; end; mD1m; end;
;asm
       call mD2m
       mov eax,[rgA]
     cmp eax,[tmp1]
             jnb C96_m1
       call m13m
   C96_m1:  call mD1m
               ret
;end; end;

C97: ;begin //m10m; rgA:=0; m27m; end;
;asm
       call m10m
       xor eax,eax
       mov [rgA],eax
       call m27m
          ret
;end; end;

C98: ;begin //m41m_a:=rgB;m41m;end;
;asm
       mov eax,[rgB]
       mov [m41m_a],eax
       call m41m
          ret
;end; end;

C99: ;begin //m41m_a:=rgC; m41m; end;
;asm
       mov eax,[rgC]
       mov [m41m_a],eax
       call m41m
          ret
;end; end;

C9A: ;begin //m41m_a:=rgD;m41m; end;
;asm
      mov eax,[rgD]
       mov [m41m_a],eax
       call m41m
           ret
;end; end;

C9B: ;begin //m41m_a:=rgE; m41m; end;
;asm
       mov eax,[rgE]
       mov [m41m_a],eax
       call m41m
          ret
;end; end;

C9C: ;begin //m41m_a:=rgH; m41m; end;
;asm
       mov eax,[rgH]
       mov [m41m_a],eax
       call m41m
          ret
;end; end;

C9D: ;begin //m41m_a:=rgL; m41m; end;
;asm
       mov eax,[rgL]
       mov [m41m_a],eax
       call m41m
          ret
;end; end;

C9E: ;begin //m74m; m57m; if m57m_Result<>0 then tmp3:=1 else tmp3:=0;
;// m85m_a:=(rgA-tmp1-tmp3); m85m; m09m; if (rgA<tmp1+tmp3) then begin m13m; end;
;// mD1m; end;
;asm
       call m74m
       call m57m
  cmp dword [m57m_Result],$00
             jz C9E_m1
 mov [tmp3],$00000001
             jmp C9E_m2
C9E_m1:    xor eax,eax
C9E_m2:   mov [tmp3],eax
       mov eax,[rgA]
     sub eax,[tmp1]
     sub eax,[tmp3]
       mov [m85m_a],eax
       call m85m
       call m09m
       mov eax,[tmp1]
     add eax,[tmp3]
     cmp eax,[rgA]
             jbe C9E_m3
       call m13m
C9E_m3: call mD1m
           ret
;end; end;

C9F: ;begin //m57m; if m57m_Result<>0 then tmp2:=$FF else tmp2:=0; m09m;
   ;//if (tmp2<>0) then begin rgF:=rgF or (fA or fC); end; m35m; end;
;asm
       call m57m
   cmp dword [m57m_Result],$00
             jz C9F_m1
 mov [tmp2],$000000ff
             jmp C9F_m2
        xor eax,eax
C9F_m1:  mov [tmp2],eax
C9F_m2:    call m09m
   cmp dword [tmp2],$00
             jz C9F_m3
       mov eax,[fA]
     or eax,[fC]
     or [rgF],eax
C9F_m3:    call m35m
            ret
;end; end;

CA0: ;begin //mA5m_a:=(rgB); mA5m; end;
;asm
       mov eax,[rgB]
       mov [mA5m_a],eax
       call mA5m
          ret
;end; end;
CA1: ;begin //mA5m_a:=(rgC); mA5m; end;
;asm
       mov eax,[rgC]
       mov [mA5m_a],eax
       call mA5m
           ret
;end; end;

CA2: ;begin //mA5m_a:=(rgD); mA5m; end;
;asm
       mov eax,[rgD]
       mov [mA5m_a],eax
       call mA5m
           ret
;end; end;

CA3: ;begin //mA5m_a:=(rgE); mA5m; end;
;asm
       mov eax,[rgE]
       mov [mA5m_a],eax
       call mA5m
           ret
;end; end;

CA4: ;begin //mA5m_a:=(rgH); mA5m; end;
;asm
       mov eax,[rgH]
       mov [mA5m_a],eax
       call mA5m
           ret
;end; end;

CA5: ;begin //mA5m_a:=(rgL); mA5m; end;
;asm
       mov eax,[rgL]
       mov [mA5m_a],eax
       call mA5m
           ret
;end; end;

CA6: ;begin //m74m; m61m_a:=tmp1; m61m; mA4m; end;
;asm
       call m74m
       mov eax,[tmp1]
       mov [m61m_a],eax
       call m61m
       call mA4m
           ret
;end; end;

CA7: ;begin // mA5m_a:=(rgA); mA5m; end;
;asm
       mov eax,[rgA]
       mov [mA5m_a],eax
       call mA5m
          ret
;end; end;

CA8: ;begin //mA6m_a:=(rgB); mA6m; end;
;asm
       mov eax,[rgB]
       mov [mA6m_a],eax
       call mA6m
            ret
;end; end;

CA9: ;begin//mA6m_a:=(rgC); mA6m; end;
;asm
       mov eax,[rgC]
       mov [mA6m_a],eax
       call mA6m
            ret
;end; end;

CAA: ;begin //mA6m_a:=(rgD); mA6m; end;
;asm
       mov eax,[rgD]
       mov [mA6m_a],eax
       call mA6m
            ret
;end; end;

CAB: ;begin //mA6m_a:=(rgE); mA6m; end;
;asm
       mov eax,[rgE]
       mov [mA6m_a],eax
       call mA6m
            ret
;end; end;

CAC: ;begin //mA6m_a:=(rgH); mA6m; end;
;asm
       mov eax,[rgH]
       mov [mA6m_a],eax
       call mA6m
            ret
;end; end;

CAD: ;'begin //mA6m_a:=(rgL); mA6m; end;
;asm
       mov eax,[rgL]
       mov [mA6m_a],eax
       call mA6m
            ret
;end; end;

CAE: ;begin //m74m; m67m_a:=tmp1; m67m; m11m; m17m; m14m; end;
;asm
       call m74m
       mov eax,[tmp1]
       mov [m67m_a],eax
       call m67m
       call m11m
       call m17m
       call m14m
           ret
;end; end;

CAF: ;begin //rgA:=0; m26m; end;
;asm
       xor eax,eax
       mov [rgA],eax
       call m26m
              ret
;end; end;

CB0: ;begin //m64m_a:=rgB; m64m; m26m; end;
;asm
       mov eax,[rgB]
       mov [m64m_a],eax
       call m64m
       call m26m
           ret
;end; end;

CB1: ;begin //m64m_a:=rgC; m64m; m26m; end;
;asm
       mov eax,[rgC]
       mov [m64m_a],eax
       call m64m
       call m26m
           ret
;end; end;

CB2: ;begin //m64m_a:=rgD; m64m; m26m; end;
;asm
       mov eax,[rgD]
       mov [m64m_a],eax
       call m64m
       call m26m
           ret
;end; end;

CB3: ;begin //m64m_a:=rgE; m64m; m26m; end;
;asm
       mov eax,[rgE]
       mov [m64m_a],eax
       call m64m
       call m26m
           ret
;end; end;

CB4: ;begin //m64m_a:=rgH; m64m; m26m; end;
;asm
       mov eax,[rgH]
       mov [m64m_a],eax
       call m64m
       call m26m
           ret
;end; end;

CB5: ;begin //m64m_a:=rgL; m64m; m26m; end;
;asm
       mov eax,[rgL]
       mov [m64m_a],eax
       call m64m
       call m26m
           ret
;end; end;

CB6: ;begin //m74m; m64m_a:=tmp1; m64m; mA4m; end;
;asm
      call m74m
       mov eax,[tmp1]
       mov [m64m_a],eax
       call m64m
       call mA4m
          ret
;end; end;

CB7: ;begin //m64m_a:=rgA; m64m; m26m; end;
;asm
       mov eax,[rgA]
       mov [m64m_a],eax
       call m64m
       call m26m
          ret
;end; end;

CB8: ;begin //m63m_a:=rgB;m63m; end;
;asm
       mov eax,[rgB]
       mov [m63m_a],eax
       call m63m
           ret
;end; end;

CB9: ;begin //m63m_a:=rgC;m63m; end;
;asm
       mov eax,[rgC]
       mov [m63m_a],eax
       call m63m
           ret
;end; end;

CBA: ;begin //m63m_a:=rgD;m63m; end;
;asm
       mov eax,[rgD]
       mov [m63m_a],eax
       call m63m
           ret
;end; end;

CBB:;begin //m63m_a:=rgE; m63m; end;
;asm
       mov eax,[rgE]
       mov [m63m_a],eax
       call m63m
           ret
;end; end;

CBC:;begin //m63m_a:=rgH; m63m; end;
;asm
       mov eax,[rgH]
       mov [m63m_a],eax
       call m63m
           ret
;end; end;

CBD:;begin //m63m_a:=rgL;m63m; end;
;asm
       mov eax,[rgL]
       mov [m63m_a],eax
       call m63m
           ret
;end; end;

CBE: ;begin //mD2m; if (rgA<tmp1) then begin m13m; end; m36m_a:=tmp1; m36m; m31m; end;
;asm
       call mD2m
       mov eax,[rgA]
     cmp eax,[tmp1]
             jnb CBE_m1
       call m13m
CBE_m1:   mov eax,[tmp1]
       mov [m36m_a],eax
       call m36m
       call m31m
             ret
;end; end;

CBF: ;//begin m10m; m27m; end;
;Begin asm
      call m10m
      call m27m
        ret
; end; end;

CC0: ;begin //mA1m; if mA1m_Result<>0 then begin m25m; end else begin m82m; end; end;
;asm
       call mA1m
   cmp dword [mA1m_Result],$00
          jz CC0_m1
       call m25m
       jmp CC0_ret
CC0_m1:   call m82m
CC0_ret:   
            ret
;end; end;

CC1: ;begin //mB8m; rgC:=mB8m_Result; mB9m; rgB:=mB9m_Result; mD3m; end;
;asm
       call mB8m
       mov eax,[mB8m_Result]
       mov [rgC],eax
       call mB9m
       mov eax,[mB9m_Result]
       mov [rgB],eax
      call mD3m
         ret
;end; end;

CC2: ;begin //mA1m; if mA1m_Result<>0 then begin m03m; end
;// else begin m28m;m29m;rgPC:=m29m_Result+((m28m_Result shl 8)); m19m; end; end;
;asm
       call mA1m
   cmp dword [mA1m_Result],$00
             jz  CC2_m1
       call m03m
       jmp CC2_m2
CC2_m1:   call m28m
       call m29m
       mov eax,[m28m_Result]
           shl eax,$08
     add eax,[m29m_Result]
       mov [rgPC],eax
       call m19m
CC2_m2:   
             ret
;end; end;

CC3: ;begin //m28m;m29m;rgPC:=m29m_Result+((m28m_Result shl 8)); m19m; end;
;asm
       call m28m
       call m29m
       mov eax,[m28m_Result]
           shl eax,$08
     add eax,[m29m_Result]
       mov [rgPC],eax
       call m19m
            ret
;end; end;

CC4: ;begin //mA1m; if mA1m_Result<>0 then begin m78m; end else
;// begin m28m;m29m;tmp1:=m29m_Result+((m28m_Result shl 8)); m50m; m02m; mB1m; end; end;
;asm
       call mA1m
   cmp dword [mA1m_Result],$00
             jz CC4_m1
       call m78m
       jmp CC4_m2
CC4_m1:  call m28m
       call m29m
       mov eax,[m28m_Result]
           shl eax,$08
     add eax,[m29m_Result]
       mov [tmp1],eax
       call m50m
       call m02m
       call mB1m
CC4_m2: 
            ret
;end; end;

CC5: ;begin //m50m; mB4m_a1:=rgC; mB4m_a2:=rgB; mB4m; mB2m; end;
;asm
       call m50m
       mov eax,[rgC]
       mov [mB4m_a1],eax
       mov eax,[rgB]
       mov [mB4m_a2],eax
       call mB4m
       call mB2m
           ret
;end; end;

CC6: ;begin //m47m; tmp2:=rgA+tmp1; m08m; m36m_a:=tmp1; m36m;
;//if (tmp2>$FF) then begin m65m; end; mD4m; end;
;asm
       call m47m
       mov eax,[rgA]
     add eax,[tmp1]
       mov [tmp2],eax
       call m08m
       mov eax,[tmp1]
       mov [m36m_a],eax
       call m36m
    cmp [tmp2],$000000ff
             jbe CC6_m1
       call m65m
    CC6_m1: call mD4m
            ret
;end; end;

CC7: ;begin //mA7m; rgPC:=0*8; m20m; end;
;asm
       call mA7m
       xor eax,eax
       mov [rgPC],eax
       call m20m
        ret

;end; end;

CC8: ;begin //m60m; if m60m_Result<>0 then begin m25m; end else begin m82m; end; end;
;asm
     call m60m
   cmp dword [m60m_Result],$00
             jz CC8_m1
       call m25m
       jmp CC8_m2
CC8_m1:  call m82m
CC8_m2:  
               ret
;end; end;

CC9: ;//begin m82m; end;
;Begin asm
      call m82m
        ret
; end; end;

CCA: ;begin //m60m; if m60m_Result<>0 then begin m03m; end else begin m77m; end; end;
;asm
       call m60m
   cmp dword [m60m_Result],$00
             jz CCA_m1
       call m03m
       jmp CCA_m2
CCA_m1:    call m77m
CCA_m2:   
               ret
;end; end;


CCB: ;// m77m;
;Begin asm
      call m77m
        ret
; end; end;

CCC: ;begin //m60m; if m60m_Result<>0 then begin m78m; end else m68m; end;
;asm
           call m60m
   cmp dword [m60m_Result],$00
             jz  CCC_m1
       call m78m
       jmp CCC_m2
CCC_m1:    call m68m
CCC_m2:    
               ret
;end; end;

CCD: ;//m68m;
;Begin asm
      call m68m
        ret
; end; end;

CCE: ;begin //m47m; m73m_a:=tmp1; m73m; if (tmp2>$FF) then begin m65m; end; mD4m; end;
;asm
       call m47m
       mov eax,[tmp1]
       mov [m73m_a],eax
       call m73m
 cmp [tmp2],$000000ff
             jbe CCE_m1
        call m65m
CCE_m1:   call mD4m
               ret
;end; end;

CCF: ;begin //mA7m; rgPC:=1*8; m20m; end;
;asm
       call mA7m
   mov [rgPC],$00000008
       call m20m
          ret
;end; end;

CD0: ;begin //m57m; if m57m_Result<>0 then begin m25m; end else begin m82m; end end;
;asm
       call m57m
   cmp dword [m57m_Result],$00
            jz CD0_m1
       call m25m
       jmp CD0_m2
CD0_m1:  call m82m
CD0_m2:   
            ret
;end; end;

CD1: ;begin //mB8m; rgE:=mB8m_Result; mB9m; rgD:=mB9m_Result; mD3m; end;
;asm
       call mB8m
       mov eax,[mB8m_Result]
       mov [rgE],eax
       call mB9m
       mov eax,[mB9m_Result]
       mov [rgD],eax
       call mD3m
               ret
;end; end;

CD2: ;begin //m57m; if m57m_Result<>0 then begin m03m; end else begin m77m; end; end;
;asm
       call m57m
   cmp dword [m57m_Result],$00
             jz  CD2_m1
       call m03m
       jmp CD2_m2
CD2_m1:   call m77m
CD2_m2: 
            ret
;end; end;

CD3: ;begin //m29m; do_output_port:=m29m_Result;do_output_bt:=rgA;do_output; mC2m; end;
;asm
;call CycleProcesEvents ;  ЦИКЛ ОБРАБОТКИ СОБЫТИЙ
       call m29m
       mov eax,[m29m_Result]
       mov [do_output_port],eax
       mov eax,[rgA]
       mov [do_output_bt],eax
        mov eax,ebx
       call do_output
       call mC2m
               ret
;end; end;

CD4: ;begin //m57m; if m57m_Result<>0 then begin m78m; end else begin m68m; end; end;
;asm
       call m57m
   cmp dword [m57m_Result],$00
             jz CD4_m1
       call m78m
       jmp CD4_m2
CD4_m1:   call m68m
CD4_m2:  
              ret
;end; end;

CD5: ;begin //m50m; mB4m_a1:=rgE;mB4m_a2:=rgD; mB4m;mB2m; end;
;asm
       call m50m
       mov eax,[rgE]
       mov [mB4m_a1],eax
       mov eax,[rgD]
       mov [mB4m_a2],eax
       call mB4m
       call mB2m
           ret
;end; end;

CD6: ;//begin mD6m;mD5m; end;
;Begin asm
      call mD6m
      call mD5m
        ret
; end; end;

CD7: ;begin //mA7m; rgPC:=2*8; m20m; end;
;asm
         call mA7m
       mov [rgPC],$00000010
         call m20m
            ret
;end; end;

CD8:; begin //m59m; if m59m_Result<>0 then begin m25m; end else begin m82m; end; end;
;asm
        call m59m
    cmp dword [m59m_Result],$00
             jz CD8_m1
       call m25m
       jmp CD8_m2
CD8_m1:   call m82m
CD8_m2: 
               ret
;end; end;

CD9:; //begin begin m82m; end; end;
;Begin asm
      call m82m
        ret
; end; end;

CDA: ;begin //m59m; if m59m_Result<>0 then begin m03m; end else begin m77m; end; end;
;asm
       call m59m
   cmp dword [m59m_Result],$00
             jz CDA_m1
       call m03m
       jmp CDA_m2
CDA_m1:   call m77m
CDA_m2:    
            ret
;end; end;

CDB: ;begin m29m; do_input_port:=m29m_Result; do_input;rgA:=do_input_Result; mC2m; end;
;//asm
;call CycleProcesEvents ;  ЦИКЛ ОБРАБОТКИ СОБЫТИЙ
       call m29m
       mov eax,[m29m_Result]
       mov [do_input_port],eax
             mov eax,ebx
       call do_input
       mov eax,[do_input_Result]
       mov [rgA],eax
         call mC2m
            ret
;//end; end;

CDC:; begin //m59m; if m59m_Result<>0 then begin m78m; end else begin m68m; end; end;
;asm
       call m59m
   cmp dword [m59m_Result],$00
             jz CDC_m1
       call m78m
       jmp CDC_m2
CDC_m1:    call m68m
CDC_m2:     
         ret
;end; end;

CDD:; //m68m;
;Begin asm
      call m68m
      ret
; end; end;

CDE: ;begin //m47m; m57m; if m57m_Result<>0 then tmp3:=1 else tmp3:=0;
 ;// m85m_a:=(rgA-tmp1-tmp3); m85m; m09m; if (rgA<tmp1+tmp3) then begin
;// m65m; end; m36m_a:=tmp1; m36m; mD5m; end;
;asm
       call m47m
       call m57m
   cmp dword [m57m_Result],$00
             jz CDE_m1
 mov [tmp3],$00000001
             jmp CDE_m2
CDE_m1:  xor eax,eax
       mov [tmp3],eax
CDE_m2:  mov eax,[rgA]
     sub eax,[tmp1]
     sub eax,[tmp3]
       mov [m85m_a],eax
       call m85m
       call m09m
       mov eax,[tmp1]
     add eax,[tmp3]
     cmp eax,[rgA]
             jbe CDE_m3
       call m65m
CDE_m3:  mov eax,[tmp1]
       mov [m36m_a],eax
       call m36m
       call mD5m
             ret
;end; end;

CDF: ;begin //mA7m; rgPC:=3*8; m20m; end;
;asm
       call mA7m
 mov [rgPC],$00000018
       call m20m
               ret
;end; end;



CE0: ;begin //m79m; if m79m_Result<>0 then begin m25m; end else begin m82m; end ; end;
;asm
       call m79m
   cmp dword [m79m_Result],$00
             jz CE0_m1
       call m25m
       jmp CE0_m2
CE0_m1:   call m82m
CE0_m2:   
            ret
;end; end;

CE1: ;begin //mB8m; rgL:=mB8m_Result; mB9m; rgH:=mB9m_Result; mD3m; end;
;asm
       call mB8m
       mov eax,[mB8m_Result]
       mov [rgL],eax
       call mB9m
       mov eax,[mB9m_Result]
       mov [rgH],eax
       call mD3m
           ret
;end; end;

CE2: ;begin //m79m; if m79m_Result<>0 then begin m03m; end else begin m77m; end; end;
;asm
       call m79m
   cmp dword [m79m_Result],$00
             jz CE2_m1
       call m03m
       jmp CE2_m2
CE2_m1:   call m77m
CE2_m2:  
               ret
;end; end;

CE3: ;begin //mB8m; tmp1:=mB8m_Result; mB7m_a:=(rgSP); mB7m; rgL:=tmp1;
;//mB9m; tmp1:=mB9m_Result; mB6m_a:=(rgSP+1); mB6m; rgH:=tmp1; clock:=clock+18; m14m; end;
;asm
         call mB8m
       mov eax,[mB8m_Result]
       mov [tmp1],eax
       mov eax,[rgSP]
       mov [mB7m_a],eax
       call mB7m
       mov eax,[tmp1]
       mov [rgL],eax
       call mB9m
       mov eax,[mB9m_Result]
       mov [tmp1],eax
       mov eax,[rgSP]
               inc eax
       mov [mB6m_a],eax
       call mB6m
       mov eax,[tmp1]
       mov [rgH],eax
   add dword [clock],$12
       call m14m
           ret
;end; end;

CE4: ;begin //m79m; if m79m_Result<>0 then begin m78m; end else begin m68m; end; end;
;asm
       call m79m
   cmp dword [m79m_Result],$00
             jz  CE4_m1
       call m78m
       jmp CE4_m2
CE4_m1:  call m68m
CE4_m2:     
               ret
;end; end;

CE5: ;begin// m50m; mB4m_a1:=rgL; mB4m_a2:=rgH; mB4m; mB2m; end;
;asm
       call m50m
       mov eax,[rgL]
       mov [mB4m_a1],eax
       mov eax,[rgH]
       mov [mB4m_a2],eax
       call mB4m
       call mB2m
           ret
;end; end;

CE6: ;begin //m29m; m61m_a:=m29m_Result; m61m; mB3m; end;
;asm
       call m29m
       mov eax,[m29m_Result]
       mov [m61m_a],eax
       call m61m
       call mB3m
          ret
;end; end;

CE7: ;begin //mA7m; rgPC:=4*8; m20m; end;
;asm
       call mA7m
    mov [rgPC],$00000020
       call m20m
          ret
;end; end;

CE8: ;begin //m58m; if m58m_Result<>0 then begin m25m; end else begin m82m; end; end;
;asm
       call m58m
   cmp dword [m58m_Result],$00
             jz CE8_m1
       call m25m
       jmp CE8_m2
CE8_m1:   call m82m
CE8_m2:
           ret
;end; end;

CE9: ;begin //rgPC:=(rgH shl 8)+rgL; m18m; end;
;asm
       mov eax,[rgH]
           shl eax,$08
     add eax,[rgL]
       mov [rgPC],eax
       call m18m
               ret
;end; end;

CEA: ;begin ///m58m; if m58m_Result<>0 then begin m03m; end else begin m77m; end; end;
;asm
       call m58m
   cmp dword [m58m_Result],$00
             jz  CEA_m1
       call m03m
       jmp CEA_m2
CEA_m1:   call m77m
CEA_m2:     
               ret
;end; end;

CEB: ;begin //tmp1:=rgD; rgD:=rgH; rgH:=tmp1; tmp1:=rgE; rgE:=rgL; rgL:=tmp1; m16m; m14m; end;
;asm
       mov eax,[rgD]
       mov [tmp1],eax
       mov eax,[rgH]
       mov [rgD],eax
       mov eax,[tmp1]
       mov [rgH],eax
       mov eax,[rgE]
       mov [tmp1],eax
       mov eax,[rgL]
       mov [rgE],eax
       mov eax,[tmp1]
       mov [rgL],eax
       call m16m
       call m14m
          ret
;end; end;

CEC: ;begin //m58m; if m58m_Result<>0 then begin m78m; end else begin m68m; end; end;
;asm
       call m58m
   cmp dword [m58m_Result],$00
             jz  CEC_m1
       call m78m
       jmp CEC_m2
CEC_m1:  call m68m
CEC_m2:    
              ret
;end; end;

CED:; //m68m;
;Begin asm
      call m68m
        ret
; end; end;

CEE: ;begin //m29m;rgA:= rgA xor m29m_Result; mB3m; end;
;asm
       call m29m
       mov eax,[m29m_Result]
     xor [rgA],eax
      call mB3m
         ret
;end; end;

CEF: ;begin //mA7m; rgPC:=5*8; m20m; end;
;asm
       call mA7m
 mov [rgPC],$00000028
       call m20m
         ret
;end; end;

CF0: ;begin //m53m; if m53m_Result<>0 then begin m25m; end else begin m82m; end; end;
;asm
       call m53m
   cmp dword [m53m_Result],$00
             jz  CF0_m1
       call m25m
       jmp CF0_m2
CF0_m1:   call m82m
CF0_m2:     
            ret
;end; end;

CF1: ;begin //mB8m; rgF:=mB8m_Result; mB9m;rgA:=mB9m_Result; mD3m; end;
;asm
       call mB8m
       mov eax,[mB8m_Result]
       mov [rgF],eax
       call mB9m
       mov eax,[mB9m_Result]
       mov [rgA],eax
       call mD3m
            ret
;end; end;

CF2: ;begin //m53m;if m53m_Result<>0 then begin m03m; end else begin m77m; end; end;
;asm
       call m53m
   cmp dword [m53m_Result],$00
             jz CF2_m1
       call m03m
       jmp CF2_m2
CF2_m1:       call m77m
CF2_m2:        
               ret
;end;end;

CF3:;// m27m;
;Begin asm
      call m27m
        ret
; end; end;

CF4: ;begin //m53m; if m53m_Result<>0 then begin m78m; end else begin m68m; end; end;
;asm
       call m53m
   cmp dword [m53m_Result],$00
             jz  CF4_m1
       call m78m
       jmp CF4_m2
CF4_m1:    call m68m
CF4_m2:    
             ret
;end;end;

CF5: ;begin //m50m; mB4m_a1:=rgF; mB4m_a2:=rgA; mB4m; mB2m; end;
;asm
       call m50m
       mov eax,[rgF]
       mov [mB4m_a1],eax
       mov eax,[rgA]
       mov [mB4m_a2],eax
       call mB4m
       call mB2m
           ret
;end;end;

CF6: ;begin //m29m;m64m_a:=m29m_Result; m64m; mB3m; end;
;asm
     call m29m
       mov eax,[m29m_Result]
       mov [m64m_a],eax
       call m64m
       call mB3m
           ret
;end;end;

CF7: ;begin //mA7m; rgPC:=6*8; m20m; end;
;asm
       call mA7m
 mov [rgPC],$00000030
       call m20m
         ret
;end;end;

CF8: ;begin //m54m; if m54m_Result<>0 then begin m25m; end else begin m82m; end; end;
;asm
       call m54m
   cmp dword [m54m_Result],$00
             jz CF8_m1
       call m25m
       jmp CF8_m2
CF8_m1: call m82m
CF8_m2: 
          ret
;end;end;

CF9: ;begin //rgSP:=(rgH shl 8)+rgL; m25m; end;
;asm
       mov eax,[rgH]
           shl eax,$08
     add eax,[rgL]
       mov [rgSP],eax
       call m25m
              ret
;end;end;

CFA: ;begin //m54m;if m54m_Result<>0 then begin m03m; end else begin m77m; end; end;
;asm
       call m54m
   cmp dword [m54m_Result],$00
             jz CFA_m1
       call m03m
             jmp CFA_m2
CFA_m1:   call m77m
CFA_m2:  
               ret

;end;end;

CFB: ;// m27m;
;Begin asm
      call m27m
        ret
; end; end;

CFC: ;begin //m54m; if m54m_Result<>0 then begin m78m; end else begin m68m; end; end;
;asm
        call m54m
   cmp dword [m54m_Result],$00
             jz CFC_m1
       call m78m
             jmp CFC_m2
CFC_m1:    call m68m
CFC_m2:    
               ret
;end;end;

CFD: ;//m68m;
;Begin asm
      call m68m
        ret
; end; end;

CFE: ;//begin mD6m;m33m; end;
;Begin asm
      call mD6m
      call m33m
        ret
; end; end;

CFF:; begin //mA7m; rgPC:=7*8; m20m; end
;   asm
      call mA7m
 mov [rgPC],$00000038
       call m20m
       ret
; end; end;
; end;
; {$R+}
;end;

;==================================================
init_table_in_case_opcode:
mov[adrs+(4*0)],C00
mov[adrs+(4*1)],C01
mov[adrs+(4*2)],C02
mov[adrs+(4*3)],C03
mov[adrs+(4*4)],C04
mov[adrs+(4*5)],C05
mov[adrs+(4*6)],C06
mov[adrs+(4*7)],C07
mov[adrs+(4*8)],C08
mov[adrs+(4*9)],C09
mov[adrs+(4*10)],C0A

mov[adrs+(4*11)],C0B
mov[adrs+(4*12)],C0C
mov[adrs+(4*13)],C0D
mov[adrs+(4*14)],C0E
mov[adrs+(4*15)],C0F
mov[adrs+(4*16)],C10
mov[adrs+(4*17)],C11
mov[adrs+(4*18)],C12
mov[adrs+(4*19)],C13
mov[adrs+(4*20)],C14

mov[adrs+(4*21)],C15
mov[adrs+(4*22)],C16
mov[adrs+(4*23)],C17
mov[adrs+(4*24)],C18
mov[adrs+(4*25)],C19
mov[adrs+(4*26)],C1A
mov[adrs+(4*27)],C1B
mov[adrs+(4*28)],C1C
mov[adrs+(4*29)],C1D
mov[adrs+(4*30)],C1E

mov[adrs+(4*31)],C1F
mov[adrs+(4*32)],C20
mov[adrs+(4*33)],C21
mov[adrs+(4*34)],C22
mov[adrs+(4*35)],C23
mov[adrs+(4*36)],C24
mov[adrs+(4*37)],C25
mov[adrs+(4*38)],C26
mov[adrs+(4*39)],C27
mov[adrs+(4*40)],C28

mov[adrs+(4*41)],C29
mov[adrs+(4*42)],C2A
mov[adrs+(4*43)],C2B
mov[adrs+(4*44)],C2C
mov[adrs+(4*45)],C2D
mov[adrs+(4*46)],C2E
mov[adrs+(4*47)],C2F
mov[adrs+(4*48)],C30
mov[adrs+(4*49)],C31
mov[adrs+(4*50)],C32

mov[adrs+(4*51)],C33
mov[adrs+(4*52)],C34
mov[adrs+(4*53)],C35
mov[adrs+(4*54)],C36
mov[adrs+(4*55)],C37
mov[adrs+(4*56)],C38
mov[adrs+(4*57)],C39
mov[adrs+(4*58)],C3A
mov[adrs+(4*59)],C3B
mov[adrs+(4*60)],C3C

mov[adrs+(4*61)],C3D
mov[adrs+(4*62)],C3E
mov[adrs+(4*63)],C3F
mov[adrs+(4*64)],C40
mov[adrs+(4*65)],C41
mov[adrs+(4*66)],C42
mov[adrs+(4*67)],C43
mov[adrs+(4*68)],C44
mov[adrs+(4*69)],C45
mov[adrs+(4*70)],C46

mov[adrs+(4*71)],C47
mov[adrs+(4*72)],C48
mov[adrs+(4*73)],C49
mov[adrs+(4*74)],C4A
mov[adrs+(4*75)],C4B
mov[adrs+(4*76)],C4C
mov[adrs+(4*77)],C4D
mov[adrs+(4*78)],C4E
mov[adrs+(4*79)],C4F
mov[adrs+(4*80)],C50

mov[adrs+(4*81)],C51
mov[adrs+(4*82)],C52
mov[adrs+(4*83)],C53
mov[adrs+(4*84)],C54
mov[adrs+(4*85)],C55
mov[adrs+(4*86)],C56
mov[adrs+(4*87)],C57
mov[adrs+(4*88)],C58
mov[adrs+(4*89)],C59
mov[adrs+(4*90)],C5A

mov[adrs+(4*91)],C5B
mov[adrs+(4*92)],C5C
mov[adrs+(4*93)],C5D
mov[adrs+(4*94)],C5E
mov[adrs+(4*95)],C5F
mov[adrs+(4*96)],C60
mov[adrs+(4*97)],C61
mov[adrs+(4*98)],C62
mov[adrs+(4*99)],C63

mov[adrs+(4*100)],C64
mov[adrs+(4*101)],C65
mov[adrs+(4*102)],C66
mov[adrs+(4*103)],C67
mov[adrs+(4*104)],C68
mov[adrs+(4*105)],C69
mov[adrs+(4*106)],C6A
mov[adrs+(4*107)],C6B
mov[adrs+(4*108)],C6C
mov[adrs+(4*109)],C6D
mov[adrs+(4*110)],C6E

mov[adrs+(4*111)],C6F
mov[adrs+(4*112)],C70
mov[adrs+(4*113)],C71
mov[adrs+(4*114)],C72
mov[adrs+(4*115)],C73
mov[adrs+(4*116)],C74
mov[adrs+(4*117)],C75
mov[adrs+(4*118)],C76
mov[adrs+(4*119)],C77
mov[adrs+(4*120)],C78

mov[adrs+(4*121)],C79
mov[adrs+(4*122)],C7A
mov[adrs+(4*123)],C7B
mov[adrs+(4*124)],C7C
mov[adrs+(4*125)],C7D
mov[adrs+(4*126)],C7E
mov[adrs+(4*127)],C7F
mov[adrs+(4*128)],C80
mov[adrs+(4*129)],C81
mov[adrs+(4*130)],C82

mov[adrs+(4*131)],C83
mov[adrs+(4*132)],C84
mov[adrs+(4*133)],C85
mov[adrs+(4*134)],C86
mov[adrs+(4*135)],C87
mov[adrs+(4*136)],C88
mov[adrs+(4*137)],C89
mov[adrs+(4*138)],C8A
mov[adrs+(4*139)],C8B
mov[adrs+(4*140)],C8C

mov[adrs+(4*141)],C8D
mov[adrs+(4*142)],C8E
mov[adrs+(4*143)],C8F
mov[adrs+(4*144)],C90
mov[adrs+(4*145)],C91
mov[adrs+(4*146)],C92
mov[adrs+(4*147)],C93
mov[adrs+(4*148)],C94
mov[adrs+(4*149)],C95
mov[adrs+(4*150)],C96

mov[adrs+(4*151)],C97
mov[adrs+(4*152)],C98
mov[adrs+(4*153)],C99
mov[adrs+(4*154)],C9A
mov[adrs+(4*155)],C9B
mov[adrs+(4*156)],C9C
mov[adrs+(4*157)],C9D
mov[adrs+(4*158)],C9E
mov[adrs+(4*159)],C9F
mov[adrs+(4*160)],CA0

mov[adrs+(4*161)],CA1
mov[adrs+(4*162)],CA2
mov[adrs+(4*163)],CA3
mov[adrs+(4*164)],CA4
mov[adrs+(4*165)],CA5
mov[adrs+(4*166)],CA6
mov[adrs+(4*167)],CA7
mov[adrs+(4*168)],CA8
mov[adrs+(4*169)],CA9
mov[adrs+(4*170)],CAA

mov[adrs+(4*171)],CAB
mov[adrs+(4*172)],CAC
mov[adrs+(4*173)],CAD
mov[adrs+(4*174)],CAE
mov[adrs+(4*175)],CAF
mov[adrs+(4*176)],CB0
mov[adrs+(4*177)],CB1
mov[adrs+(4*178)],CB2
mov[adrs+(4*179)],CB3
mov[adrs+(4*180)],CB4

mov[adrs+(4*181)],CB5
mov[adrs+(4*182)],CB6
mov[adrs+(4*183)],CB7
mov[adrs+(4*184)],CB8
mov[adrs+(4*185)],CB9
mov[adrs+(4*186)],CBA
mov[adrs+(4*187)],CBB
mov[adrs+(4*188)],CBC
mov[adrs+(4*189)],CBD
mov[adrs+(4*190)],CBE

mov[adrs+(4*191)],CBF
mov[adrs+(4*192)],CC0
mov[adrs+(4*193)],CC1
mov[adrs+(4*194)],CC2
mov[adrs+(4*195)],CC3
mov[adrs+(4*196)],CC4
mov[adrs+(4*197)],CC5
mov[adrs+(4*198)],CC6
mov[adrs+(4*199)],CC7
mov[adrs+(4*200)],CC8

mov[adrs+(4*201)],CC9
mov[adrs+(4*202)],CCA
mov[adrs+(4*203)],CCB
mov[adrs+(4*204)],CCC
mov[adrs+(4*205)],CCD
mov[adrs+(4*206)],CCE
mov[adrs+(4*207)],CCF
mov[adrs+(4*208)],CD0
mov[adrs+(4*209)],CD1
mov[adrs+(4*210)],CD2

mov[adrs+(4*211)],CD3
mov[adrs+(4*212)],CD4
mov[adrs+(4*213)],CD5
mov[adrs+(4*214)],CD6
mov[adrs+(4*215)],CD7
mov[adrs+(4*216)],CD8
mov[adrs+(4*217)],CD9
mov[adrs+(4*218)],CDA
mov[adrs+(4*219)],CDB
mov[adrs+(4*220)],CDC

mov[adrs+(4*221)],CDD
mov[adrs+(4*222)],CDE
mov[adrs+(4*223)],CDF
mov[adrs+(4*224)],CE0
mov[adrs+(4*225)],CE1
mov[adrs+(4*226)],CE2
mov[adrs+(4*227)],CE3
mov[adrs+(4*228)],CE4
mov[adrs+(4*229)],CE5
mov[adrs+(4*230)],CE6

mov[adrs+(4*231)],CE7
mov[adrs+(4*232)],CE8
mov[adrs+(4*233)],CE9
mov[adrs+(4*234)],CEA
mov[adrs+(4*235)],CEB
mov[adrs+(4*236)],CEC
mov[adrs+(4*237)],CED
mov[adrs+(4*238)],CEE
mov[adrs+(4*239)],CEF
mov[adrs+(4*240)],CF0

mov[adrs+(4*241)],CF1
mov[adrs+(4*242)],CF2
mov[adrs+(4*243)],CF3
mov[adrs+(4*244)],CF4
mov[adrs+(4*245)],CF5
mov[adrs+(4*246)],CF6
mov[adrs+(4*247)],CF7
mov[adrs+(4*248)],CF8
mov[adrs+(4*249)],CF9
mov[adrs+(4*250)],CFA

mov[adrs+(4*251)],CFB
mov[adrs+(4*252)],CFC
mov[adrs+(4*253)],CFD
mov[adrs+(4*254)],CFE
mov[adrs+(4*255)],CFF

ret
;/конец = Таблица Case of
;======================================================

 ; //выполнение комманд процессора
;//{ДЛЯ i8080_do_opcodes }
i8080_do_opcodes:
;//1209: begin
               ;push ebx
             ;mov ebx,eax
;//1211: clock:=0; tmp1:=0; tmp2:=0; tmp3:=0; //бнулим :-)
             xor eax,eax
       mov [clock],eax
       mov [tmp1],eax
       mov [tmp2],eax
       mov [tmp3],eax
;//1212: while (clock < i8080_do_opcodes_nb_cycles) do begin
       mov eax,[clock]
     cmp eax,[i8080_do_opcodes_nb_cycles]
             jnb  i8080_do_opcodes_nb_cycles_ret
;//1213: do_read_addr:=(rgPC);do_read;opcode:=do_read_Result;
i8080_do_opcodes_nb_cycles_m1:
    and [rgPC],$0000ffff
           mov eax,[rgPC]
       mov [do_read_addr],eax

       call do_read
       mov eax,[do_read_result]
       mov [opcode],eax
;///1214: i8080_do_opcodes_case_opcode_of; end;
             ;mov eax,ebx
       call i8080_do_opcodes_case_opcode_of
;//1212: while (clock < i8080_do_opcodes_nb_cycles) do begin
       mov eax,[clock]
    cmp eax,[i8080_do_opcodes_nb_cycles]
            jb i8080_do_opcodes_nb_cycles_m1
;//1216: end;
i8080_do_opcodes_nb_cycles_ret:  ;      pop ebx
               ret
;================================


i8080_do_opcodes_case_opcode_of:
;call CycleProcesEvents ;  ЦИКЛ ОБРАБОТКИ СОБЫТИЙ
  mov eax,[opcode]
 Call dword [eax*4+adrs] 
 ret

8

uKeyBoard.asm

Код:
TableKeyDopINIT:
;TableKeyDop rw 256
mov[TableKeyDop+(4*77)],$0000ff30;  ;//{ВВЕРХ}
mov[TableKeyDop+(4*72)],$0000ff31;  ;//{ВВЕРХ}
mov[TableKeyDop+(4*75)],$0000ff32;  ;//ВЛЕВО;
mov[TableKeyDop+(4*80)],$0000ff33;  ;//ВНИЗ;

mov[TableKeyDop+(4*56)],$62FF ;  //  (ALT) = СУ

mov[TableKeyDop+(4*29)],$35FF ;  //  (R-CTRL) =   // ЛАТ
mov[TableKeyDop+(4*82)],$03FF ;  //   Insert = ГТ
mov[TableKeyDop+(4*73)],$14FF ; // PageUp =  ПС
mov[TableKeyDop+(4*79)],$34FF ;  //  (END) = _
mov[TableKeyDop+(4*71)],$FF20 ;  // Home = Home
mov[TableKeyDop+(4*81)],$FF10 ;  // (PageDown) = (П/Д)

; РУС и енгл
mov[TableKeyOsnEngl+(4*42)],$33FF  ;  L-Shift // ВР
mov[TableKeyOsnEngl+(4*54)],$70FF  ;  R-Shift // НР
mov[TableKeyOsnRus+(4*42)],$33FF  ;  L-Shift // ВР
mov[TableKeyOsnRus+(4*54)],$70FF  ;  R-Shift // НР

mov[TableKeyOsnEngl+(4*56)], $62FF ;  //  (ALT) = СУ
mov[TableKeyOsnRus+(4*56)], $62FF ;  //  (ALT) = СУ

mov[TableKeyOsnEngl+(4*29)],$61FF ;  //  (L-CTRL) = РУС
mov[TableKeyOsnRus+(4*29)], $61FF ;  //  (L-CTRL) = РУС

mov[TableKeyOsnEngl+(4*1)],$40FF ;  // esc - СТР
mov[TableKeyOsnRus+(4*1)], $40FF ;  // esc - СТР


mov[TableKeyOsnEngl+(4*59)],$FF12 ;  // (F1) = (F1 чмл)
mov[TableKeyOsnRus+(4*59)], $FF12 ;  // (F1) = (F1 чмл)

mov[TableKeyOsnEngl+(4*60)],$FF13 ;  // (F2) = (F2 змл)
mov[TableKeyOsnRus+(4*60)], $FF13 ;  // (F2) = (F2 змл)

mov[TableKeyOsnEngl+(4*61)],$FF23 ;  // F3
mov[TableKeyOsnRus+(4*61)], $FF23 ;  // F3

mov[TableKeyOsnEngl+(4*62)],$FF22 ;   // F4
mov[TableKeyOsnRus+(4*62)], $FF22 ;   // F4

mov[TableKeyOsnEngl+(4*63)],$FF21 ;  // F5
mov[TableKeyOsnRus+(4*63)], $FF21 ;  // F5

mov[TableKeyOsnEngl+(4*64 )],$41FF ;  // (F6) - (G)
mov[TableKeyOsnRus+(4*64)], $41FF ;  // (F6) - (G)

mov[TableKeyOsnEngl+(4*65)],$42FF ;  // (F7) - (B)
mov[TableKeyOsnRus+(4*65)], $42FF ;  // (F7) - (B)

mov[TableKeyOsnEngl+(4*66)],$FF03 ;  // (F8) = ("R")
mov[TableKeyOsnRus+(4*66)], $FF03 ;  // (F8) = ("R")
  
mov[TableKeyOsnEngl+(4*67)],$FF11  ;  // (F9) = (F0)
mov[TableKeyOsnRus+(4*67)], $FF11  ;  // (F9) = (F0)

mov[TableKeyOsnEngl+(4*68)],$FF02  ;  // (F10) = (Звук)
mov[TableKeyOsnRus+(4*68)], $FF02  ;  // (F10) = (Звук)

mov[TableKeyOsnEngl+(4*87)],$FF01 ;  // (F11) = (CD)
mov[TableKeyOsnRus+(4*87)], $FF01 ;  // (F11) = (CD)

mov[TableKeyOsnEngl+(4*88)],$FF00 ;  // (F12) = (ПЧ)
mov[TableKeyOsnRus+(4*88)], $FF00 ;  // (F12) = (ПЧ)



;   // Основная клавиатура  соответствие при английской раскладке
mov[TableKeyOsnEngl+(4*7)],$00FF ;  //   6
mov[TableKeyOsnEngl+(4*8)],$01FF ;  //   7
mov[TableKeyOsnEngl+(4*9)],$02FF ;  //   8

mov[TableKeyOsnEngl+(4*15)],$04FF ;  //   ТАБ 
mov[TableKeyOsnEngl+(4*12)],$05FF ;  // (-_) = (-=)
mov[TableKeyOsnEngl+(4*11)],$06FF ;  //   0
mov[TableKeyOsnEngl+(4*10)],$07FF ;  //   9
;                  {1}
mov[TableKeyOsnEngl+(4*34)],$10FF ;  //   G
mov[TableKeyOsnEngl+(4*26)],$11FF ;  //  [
mov[TableKeyOsnEngl+(4*27)],$12FF ;  // ]
mov[TableKeyOsnEngl+(4*28)],$13FF ;  // ENTER

mov[TableKeyOsnEngl+(4*39)],$15FF ;  // (:;ж) = (:*)
mov[TableKeyOsnEngl+(4*35)],$16FF ;  //   H
mov[TableKeyOsnEngl+(4*44)],$17FF ;  //   Z
;                   {2}
mov[TableKeyOsnEngl+(4*19)],$20FF ;  //   R
mov[TableKeyOsnEngl+(4*24)],$21FF ;  //   O
mov[TableKeyOsnEngl+(4*38)],$22FF ;  //   L
mov[TableKeyOsnEngl+(4*14)],$23FF ;  //   ЗБ
mov[TableKeyOsnEngl+(4*52)],$24FF ;  // (.>ю) = (.>)
mov[TableKeyOsnEngl+(4*43)],$25FF ;  // (\/|) = (\)
mov[TableKeyOsnEngl+(4*47)],$26FF ;  //  V
mov[TableKeyOsnEngl+(4*32)],$27FF ;  //  D
;                   {3}
mov[TableKeyOsnEngl+(4*57)],$30FF ;  // Пробел
mov[TableKeyOsnEngl+(4*48)],$31FF ;  //  B
;                   {4}


mov[TableKeyOsnEngl+(4*6)],$43FF ;  //   5
mov[TableKeyOsnEngl+(4*5)],$44FF ;  //   4
mov[TableKeyOsnEngl+(4*4)],$45FF ;  //   3
mov[TableKeyOsnEngl+(4*3)],$46FF ;  //   2
mov[TableKeyOsnEngl+(4*2)],$47FF ;  //   1
;                   {5}
;//       50 и 51 -пусто по таблице
mov[TableKeyOsnEngl+(4*36)],$52FF ;  //   J
mov[TableKeyOsnEngl+(4*49)],$53FF ;  //   N
mov[TableKeyOsnEngl+(4*18)],$54FF ;  //   E
mov[TableKeyOsnEngl+(4*37)],$55FF ;  //   K
mov[TableKeyOsnEngl+(4*22)],$56FF ;  //   U
mov[TableKeyOsnEngl+(4*46)],$57FF ;  //   C
;                        {6}
mov[TableKeyOsnEngl+(4*41)],$60FF ;  //  (`~)=(;+)


mov[TableKeyOsnEngl+(4*25)],$63FF ;  //   P
mov[TableKeyOsnEngl+(4*30)],$64FF ;  //   A
mov[TableKeyOsnEngl+(4*17)],$65FF ;  //   W
mov[TableKeyOsnEngl+(4*21)],$66FF ;  //   Y
mov[TableKeyOsnEngl+(4*33)],$67FF ;  //   F
;                      {7}
mov[TableKeyOsnEngl+(4*16)],$71FF ;  //   Q
mov[TableKeyOsnEngl+(4*13)],$72FF ;  //   (+=) = (^)
mov[TableKeyOsnEngl+(4*45)],$73FF ;  //   X
mov[TableKeyOsnEngl+(4*20)],$74FF ;  //   T
mov[TableKeyOsnEngl+(4*23)],$75FF ;  //   I
mov[TableKeyOsnEngl+(4*50)],$76FF ;  //   M
mov[TableKeyOsnEngl+(4*31)],$77FF ;  //   S
mov[TableKeyOsnEngl+(4*40)],$32FF ;  // ("'ЄєЭэ)= (@)
mov[TableKeyOsnEngl+(4*51)],$37FF ;  // (,<) = (,)
mov[TableKeyOsnEngl+(4*53)],$36FF ;  // (/?)= (/)
; - Конец основной англ.


;    // Основная клавиатура  соответствие при РУССКАЯ РАСКЛАДКИ
 mov[TableKeyOsnRus+(4*7)], $00FF ;  //   6
 mov[TableKeyOsnRus+(4*8)], $01FF ;  //   7
 mov[TableKeyOsnRus+(4*9)], $02FF ;  //   8
 
 mov[TableKeyOsnRus+(4*15)], $04FF ;  //   ТАБ
 mov[TableKeyOsnRus+(4*12)], $05FF ;  // (-_) = (-=)
 mov[TableKeyOsnRus+(4*11)], $06FF ;  //   0
 mov[TableKeyOsnRus+(4*10)], $07FF ;  //   9
;                  {1}
 mov[TableKeyOsnRus+(4*22)], $10FF ;  //   Г
 mov[TableKeyOsnRus+(4*23)], $11FF ;  // Ш
 mov[TableKeyOsnRus+(4*24)], $12FF ;  // Щ
 mov[TableKeyOsnRus+(4*28)], $13FF ;  // ENTER
 
 mov[TableKeyOsnRus+(4*27)], $15FF ;  // (:;ж) = (Ж)
 mov[TableKeyOsnRus+(4*26)], $16FF ;  //   Х
 mov[TableKeyOsnRus+(4*25)], $17FF ;  //   З
;                   {2}
 mov[TableKeyOsnRus+(4*35)], $20FF ;  //   Р
 mov[TableKeyOsnRus+(4*36)], $21FF ;  //   О
 mov[TableKeyOsnRus+(4*37)], $22FF ;  //  Л
 mov[TableKeyOsnRus+(4*14)], $23FF ;  // ЗБ
 mov[TableKeyOsnRus+(4*43)], $24FF ;  // (\|) =
 mov[TableKeyOsnRus+(4*40)], $25FF ;  // Э
 mov[TableKeyOsnRus+(4*39)], $26FF ;  //  Ж
 mov[TableKeyOsnRus+(4*38)], $27FF ;  // Д
;                   {3}
 mov[TableKeyOsnRus+(4*57)], $30FF ;  // Пробел
 mov[TableKeyOsnRus+(4*51)], $31FF ;  // Б
 mov[TableKeyOsnRus+(4*52)], $32FF ;  // Ю
;
 mov[TableKeyOsnRus+(4*53)], $36FF ;  // / (+=) = (,)
 mov[TableKeyOsnRus+(4*13)], $37FF ;  // (,<) = (+=)
;                   {4}
 mov[TableKeyOsnRus+(4*6)], $43FF ;  //   5
 mov[TableKeyOsnRus+(4*5)], $44FF ;  //   4
 mov[TableKeyOsnRus+(4*4)], $45FF ;  //   3
 mov[TableKeyOsnRus+(4*3)], $46FF ;  //   2
 mov[TableKeyOsnRus+(4*2)], $47FF ;  //   1
;                   {5}
;//                       50 и 51 -пусто по таблице
 mov[TableKeyOsnRus+(4*16)], $52FF ;  //  Й
 mov[TableKeyOsnRus+(4*21)], $53FF ;  //   Н
 mov[TableKeyOsnRus+(4*20)], $54FF ;  //   Е
 mov[TableKeyOsnRus+(4*19)], $55FF ;  //   К
 mov[TableKeyOsnRus+(4*18)], $56FF ;  //   У
 mov[TableKeyOsnRus+(4*17)], $57FF ;  //   Ц
;                        {6}
 mov[TableKeyOsnRus+(4*41)], $60FF ;  //  (`~)=(;+)


 mov[TableKeyOsnRus+(4*34)], $63FF ;  //   П
 mov[TableKeyOsnRus+(4*33)], $64FF ;  //   А
 mov[TableKeyOsnRus+(4*32)], $65FF ;  //   В
 mov[TableKeyOsnRus+(4*31)], $66FF ;  //   Ы
 mov[TableKeyOsnRus+(4*30)], $67FF ;  //   Ф
;                      {7}
 mov[TableKeyOsnRus+(4*44)], $71FF ;  //   Я
 mov[TableKeyOsnRus+(4*45)], $72FF ;  //   Ч
 mov[TableKeyOsnRus+(4*50)], $73FF ;  //   Ь
 mov[TableKeyOsnRus+(4*49)], $74FF ;  //   Т
 mov[TableKeyOsnRus+(4*48)], $75FF ;  //   И
 mov[TableKeyOsnRus+(4*47)], $76FF ;  //   M
 mov[TableKeyOsnRus+(4*46)], $77FF ;  //   С
ret


;Procedure readmask2; label readmask2_m1,readmask2_m2,readmask2_m3,readmask2_m4,readmask2_ret; // маска клавы
readmask_keynum rd 1
readmask_Result rd 1
readmask2:
  mov [readmask_Result], 0
   mov eax,[readmask_keynum]
cmp [ScanCodeKeyExt],1
  jne readmask2_OSN;
; дополнительная
   mov eax,[eax*4+TableKeyDop]
jmp readmask2_retd
 
;Основная 
readmask2_OSN:
cmp [ScanCodeKeyExt],0
  jne readmask2_retd;
 
 ;//KYB_MODE ( BE1DH (48669)) 7 бит =0, значит АНГЛ Раскадка
 ;If (b and 128)=0 then result:=Key_engl[keynum] else
  ;result:=Key_Rus[keynum]; 
      xor ebx,ebx 
      mov bl, byte [memoryM+48669];
      test bl, 128
      jnz readmask2_rus
      
readmask2_engl:
    mov eax,[eax*4+TableKeyOsnEngl]; англ.
      jmp readmask2_retd
      
readmask2_rus:       
mov eax,[eax*4+TableKeyOsnRus] ; рус      

readmask2_retd:
mov [readmask_Result], eax
 ret
;
;procedure kbdA; label kbd_m1,kbd_m2,kbd_m3,kbd_ret;// по маске вкл выкл клавишу
;begin
;  asm
;// uKeyBoard.pas.111: kbd_bcol:=(kbd_mask SHR 12) and $0F; kbd_brow:=(kbd_mask SHR 8) and $0F;
kbd_mask rd 1
kbd_press rd 1
kbd_brow rd 1
kbd_erow rd 1
kbd_bcol rd 1
kbd_ecol rd 1
kbdA:
       mov eax,[kbd_mask]
	   shr eax,$0c
	   and eax,$0f
       mov [kbd_bcol],eax
       mov eax,[kbd_mask]
	   shr eax,$08
	   and eax,$0f
       mov [kbd_brow],eax
;//uKeyBoard.pas.112: kbd_ecol:=(kbd_mask SHR 4) and $0F; kbd_erow:=(kbd_mask SHR 0) and $0F;
       mov eax,[kbd_mask]
	   shr eax,$04
	   and eax,$0f
       mov [kbd_ecol],eax
       mov eax,[kbd_mask]
	   shr eax,$00
	   and eax,$0f
       mov [kbd_erow],eax
;//uKeyBoard.pas.113: if ((kbd_brow<8) and (kbd_bcol<8)) then
   cmp dword [kbd_brow], dword $08
     jnb kbd_m1
   cmp dword [kbd_bcol],$08
     jnb kbd_m1
;//uKeyBoard.pas.115: if kbd_press=1 then begin Rkbd_base_a:=kbd_bcol;Rkbd_base;
   cmp dword [kbd_press],$01
	     jnz kbd_m2
       mov eax, Rkbd_base_a
     mov edx,[kbd_bcol]
	     mov [eax],edx
       call Rkbd_base
;//uKeyBoard.pas.116: Wkbd_base_a:=kbd_bcol;Wkbd_base_b:=(Rkbd_base_result or (1 SHL kbd_brow));Wkbd_base; end
       mov eax, Wkbd_base_a
     mov edx,[kbd_bcol]
	     mov [eax],edx
     mov ecx,[kbd_brow]
       mov eax,$00000001
	     shl eax,cl
     mov edx, Rkbd_base_result
	     or eax,[edx]
     mov edx, Wkbd_base_b
	     mov [edx],eax
       call Wkbd_base
	     jmp kbd_m1
;//uKeyBoard.pas.117: else begin Rkbd_base_a:=kbd_bcol;Rkbd_base;
kbd_m2:     mov eax,  Rkbd_base_a
     mov edx,[kbd_bcol]
	     mov [eax],edx
       call Rkbd_base
;//uKeyBoard.pas.118: Wkbd_base_a:=kbd_bcol;Wkbd_base_b:=(Rkbd_base_result and (not(1 SHL kbd_brow))); Wkbd_base; end;
       mov eax, Wkbd_base_a
     mov edx,[kbd_bcol]
	     mov [eax],edx
     mov ecx,[kbd_brow]
       mov eax,$00000001
	     shl eax,cl
	     not eax
     mov edx,  Rkbd_base_result
	     and eax,[edx]
     mov edx,  Wkbd_base_b
	     mov [edx],eax
       call Wkbd_base
;//uKeyBoard.pas.120: if ((kbd_erow<8) and (kbd_ecol<4)) then
kbd_m1:  cmp dword [kbd_erow],$08
     jnb kbd_ret
   cmp dword [kbd_ecol],$04
     jnb kbd_ret
;//uKeyBoard.pas.121: begin Rkbd_ext_a:=kbd_ecol;Rkbd_ext;
       mov eax, Rkbd_ext_a
     mov edx,[kbd_ecol]
	     mov [eax],edx
       call Rkbd_ext
;//uKeyBoard.pas.122: if (kbd_press=1) then begin Wkbd_ext_a:=kbd_ecol;Wkbd_ext_b:= (Rkbd_ext_result or (1 SHL kbd_erow));Wkbd_ext;
   cmp dword [kbd_press],$01
	     jnz kbd_m3
       mov eax, Wkbd_ext_a
     mov edx,[kbd_ecol]
	     mov [eax],edx
     mov ecx,[kbd_erow]
       mov eax,$00000001
	     shl eax,cl
     mov edx, Rkbd_ext_result
	     or eax,[edx]
     mov edx, Wkbd_ext_b
	     mov [edx],eax
       call Wkbd_ext
	     jmp kbd_ret
;//uKeyBoard.pas.123: end else begin Rkbd_ext_a:=kbd_ecol;Rkbd_ext; Wkbd_ext_a:=kbd_ecol;Wkbd_ext_b:=(Rkbd_ext_result and (not(1 SHL kbd_erow)));Wkbd_ext; end;
kbd_m3:      mov eax, Rkbd_ext_a
     mov edx,[kbd_ecol]
	     mov [eax],edx
       call Rkbd_ext
       mov eax, Wkbd_ext_a
     mov edx,[kbd_ecol]
	     mov [eax],edx
     mov ecx,[kbd_erow]
       mov eax,$00000001
	     shl eax,cl
	     not eax
     mov edx, Rkbd_ext_result
	     and eax,[edx]
     mov edx,  Wkbd_ext_b
	     mov [edx],eax
       call Wkbd_ext
;//uKeyBoard.pas.126: end;
kbd_ret:	     ret
;end;end;

;======================================
KeyBoardInit:
mov eax,66
mov ebx,1
mov ecx,1 ;     * 0 = обычный (ASCII-символы)    * 1 = сканкоды
int 0x40
ret
;======================================
fPause dd 0 ; 0 - пауза отключена
PausePR:
xor [fPause],$ffffffff
ret
  

KeyProcess2:
call ScanCodeKey
;cmp [fPause],0
;  jnz KeyProcess2_m1; 
mov eax,[ScanCodeKey2]
mov [readmask_keynum],eax
           call readmask2
cmp [readmask_Result],0
jz KeyProcess2_m1 ; если нет клавиши в таблице         
       mov eax,[readmask_Result]
       mov [kbd_mask],eax
  mov eax, [ScanCodeKeyUD]; если 0 - отжата, если 1 -нажата
  mov [kbd_press],eax
     call kbdA
     mov [ScanCodeKeyExt],0
    ret
KeyProcess2_m1: 
    ; пауза
mov eax,[ScanCodeKey1]
  cmp eax,211
  jnz KeyProcess2_ret
  call PausePR
mov [ScanCodeKeyExt],0
;mov [ScanCodeKey2],0  
KeyProcess2_ret:  ret
  

9

uLVComp.asm

Код:
Sign_begin_data: db 'BEGIN DATA' ; метка начала данных, для генерации КОС-файла
memoryM db \
..................

portsM db \
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 

flagsM db \
70,2,2,6,2,6,6,2,2,6,6,2,6,2,2,6,2,6,6,\
2,6,2,2,6,6,2,2,6,2,6,6,2,2,6,6,2,6,2,2,\
6,6,2,2,6,2,6,6,2,6,2,2,6,2,6,6,2,2,6,6,\
2,6,2,2,6,2,6,6,2,6,2,2,6,6,2,2,6,2,6,6,\
2,6,2,2,6,2,6,6,2,2,6,6,2,6,2,2,6,6,2,2,\
6,2,6,6,2,2,6,6,2,6,2,2,6,2,6,6,2,6,2,2,\
6,6,2,2,6,2,6,6,2,130,134,134,130,134,130,130,134,134,130,130,\
134,130,134,134,130,134,130,130,134,130,134,134,130,130,134,134,130,134,130,130,\
134,134,130,130,134,130,134,134,130,130,134,134,130,134,130,130,134,130,134,134,\
130,134,130,130,134,134,130,130,134,130,134,134,130,134,130,130,134,130,134,134,\
130,130,134,134,130,134,130,130,134,130,134,134,130,134,130,130,134,134,130,130,\
134,130,134,134,130,130,134,134,130,134,130,130,134,134,130,130,134,130,134,134,\
130,134,130,130,134,130,134,134,130,130,134,134,130,134,130,130,134 

rgA dd 0
rgB dd 0
rgC dd 0
rgD dd 0
rgE dd 0
rgH dd 0
rgL dd 0
rgF dd 0
rgSP dd 0
rgPC dd $0000c000
fS_ dd 128
fZ dd 64
f5 dd 32
fA dd 16
f3 dd 8
fP dd 4
f1 dd 2
fC dd 1
;===============================
opcodes_to_run: dd 43500 ; 68500 - винде 43500- в кос(49,42) в КВ - (59,03)
GraphicsMode dd 2 ; графический режим  0- 256х256 ; 1 -512х512 2- 768х512
TimerNumber: dd 3 ; номер движка таймера
TimerDelay: dd 2 ; задержка
;===============================
LVColBlack dd 0
LVColLime dd $00FF00; 
LVColBlue dd $0000FF;
LVColRed dd $FF0000;
;===============================



10

uMem.asm

Код:
    ;// Модуль доступа к памяти портам и т.д. и процедуры обрабатывающие их
;=======================================
    do_write_addr rd 1
    do_write_bt rd 1
do_write:
;//319: begin
;//321: if do_write_addr> $FFFF then do_write_addr:=$FFFF;
	 cmp [do_write_addr],$0000ffff
             jbe do_write_m1
     mov [do_write_addr],$0000ffff
;//322: if (do_write_addr>=$C000) then
do_write_m1:cmp [do_write_addr],$0000c000
	jnb do_write_ret
;//324: Rports_a:=$C2;Rports; if ((Rports_result and 2)<>0) then begin Wmemory_A:=do_write_addr; Wmemory_B:=do_write_bt; Wmemory; end else
mov edx,$c2
   xor ebx,ebx
   mov bl,[portsM+edx]
   test bl,$02
          jz do_write_m2
       mov eax,[do_write_addr]

      mov edx,[do_write_bt]
      mov [eax+memoryM],dl

             jmp do_write_ret
;//325: if (do_write_addr<$4000) then begin exit; end else
do_write_m2: cmp [do_write_addr],$00004000
             jb do_write_ret
;//326: if (do_write_addr<$8000) then begin Wvideo_a:=(do_write_addr-$4000);Wvideo_b:=do_write_bt; Wvideo; end else
 cmp [do_write_addr],$00008000
             jnb do_write_m3
       mov eax,[do_write_addr]
       sub eax,$00004000

      mov edx,[do_write_bt]
      mov [eax+videoM],dl

             jmp do_write_ret
;//327: begin Wmemory_A:=do_write_addr; Wmemory_B:=do_write_bt; Wmemory; end;
do_write_m3:    mov eax,[do_write_addr]

      mov edx,[do_write_bt]
      mov [eax+memoryM],dl
;//329: end;
do_write_ret:
               ret
;=======================================
    do_write2_a_lo rd 1
    do_write2_a_hi rd 1
    do_write2_bt rd 1
do_write2:
;pusha
;popa
;//375: begin {$R-} do_write_addr:=do_write2_a_lo+(do_write2_a_hi SHL 8);
     mov edx,[do_write2_a_hi]
     shl edx,$08
     add edx,[do_write2_a_lo]
     mov [do_write_addr],edx
;//376: do_write_bt:=do_write2_bt;do_write; {$R+}end;
     mov edx,[do_write2_bt]
     mov [do_write_bt],edx
       call do_write
;//376: do_write_bt:=do_write2_bt;do_write; {$R+}end;
              ret
;=======================================
    do_read_addr rd 1
    do_read_result:rd 1
do_read:
; //;237: begin
;//uMainDA.pas.239: if do_read_addr> $FFFF then do_read_addr:=$FFFF;
 and [do_read_addr],$0000ffff

;//;240: RPorts_a:=$C2;RPorts; if ((RPorts_result and 2)<>0) then
do_read_m1:

mov edx,dword $c2
   xor ebx,ebx
   mov bl,[portsM+edx]
 

   test ebx, dword $02
             jz do_read_m2

;//;241: begin Rmemory_A:=do_read_addr; Rmemory; do_read_result:= Rmemory_result; end

    mov edx,[do_read_addr]
    xor ebx,ebx
    mov bl,[memoryM+edx]
    mov [do_read_result],ebx     

do_read_ret:
              ret

;//uMainDA.pas.242: else if (do_read_addr>$7FFF) then begin Rmemory_A:=do_read_addr; //Rmemory; do_read_result := Rmemory_result; end
do_read_m2: cmp [do_read_addr],$00007fff
             jbe do_read_m3
    mov edx,[do_read_addr]
    xor ebx,ebx
    mov bl,[memoryM+edx]
    mov [do_read_result],ebx
             jmp do_read_ret

;//uMainDA.pas.243: else if (do_read_addr<$4000) then begin do_read_result := 0; end else
do_read_m3: cmp [do_read_addr],$00004000
             jnb do_read_m4
             xor eax,eax
       mov [do_read_result],eax
             jmp do_read_ret

;//uMainDA.pas.244: begin Rvideo_a:=(do_read_addr-$4000); Rvideo; do_read_result := //Rvideo_result; end;
do_read_m4:   mov eax,[do_read_addr]
       sub eax,$00004000

       xor ebx,ebx
       mov bl,[videoM+eax]
       mov [do_read_result],ebx
               ret
;===============================================
    do_read2_a_lo rd 1
    do_read2_a_hi rd 1
    do_read2_result rd 1
do_read2:
;//;301: begin {$R-} do_read_addr:=(do_read2_a_lo+(do_read2_a_hi SHL 8));do_read; do_read2_result:=do_read_result; {$R+}end;
     mov edx,[do_read2_a_hi]
          shl edx,$08
     add edx,[do_read2_a_lo]
     mov [do_read_addr],edx
       call do_read
       mov eax,[do_read_result]
       mov [do_read2_result],eax
;//;301: begin {$R-} do_read_addr:=(do_read2_a_lo+(do_read2_a_hi SHL 8));do_read; do_read2_result:=do_read_result; {$R+}end;
               ret
;===============================================
do_input_port rd 1
    do_input_Result rd 1
do_input_C2:; // работа со значениями портов in
;//;396: Begin Rports_a:=$C2;Rports; do_input_Result:=Rports_result; end;
   xor ebx,ebx
   mov bl,[portsM+$000000c2]
mov [do_input_Result],ebx
;//;396: Begin Rports_a:=$C2;Rports; do_input_Result:=Rports_result; end;
ret
;=======================================
do_input_D1:; // работа со значениями портов in
;//410: Begin
               push ebx
               push esi
               push edi
               push ebp
             mov edi,eax
;//411: Rports_a:=$D0;Rports; do_input_D0:=not Rports_result; r:=0;
;//	 mov [Rports_a],byte $000000d0
             mov eax,edi
  Push ebx
   xor edx,edx
   mov dl,[portsM+$000000d0]
   pop ebx
   
   mov esi,edx             
             not esi
             xor ebp,ebp
;//412: For i:=0 to 7 do  begin
             xor ebx,ebx
;//413: if ((do_input_D0 and (1 SHL i))<>0) then
do_input_D1_m2:  mov ecx,ebx
       mov eax,$00000001
             shl eax,cl
             test eax,esi
             jz do_input_D1_m1
;//414: begin rkbd_base_a:=i;rkbd_base; r:=(r or Rkbd_base_result); end;
     mov [Rkbd_base_a],ebx
             mov eax,edi
       call Rkbd_base
     or ebp,[Rkbd_base_result]
;//uMainDA.pas.415: end;
do_input_D1_m1:  inc ebx
;//412: For i:=0 to 7 do  begin
           cmp ebx,$08
             jnz do_input_D1_m2
;//416: do_input_Result:= ((not r) and $FF);
             not ebp
     and ebp,$000000ff
     mov [do_input_Result],ebp
;//417: end;
               pop ebp
               pop edi
               pop esi
               pop ebx
               ret 
;=======================================
do_input_D2:
;//513: Begin
               push ebx
               push esi
               push edi
               push ebp
             mov edi,eax
;//514: begin Rports_a:=$D2;Rports; do_input_D2_:= not Rports_result; r:=0;
             mov eax,edi
   xor ebx,ebx
   mov bl,[portsM+$000000d2]
  mov esi,ebx
             not esi
             xor ebp,ebp
;//515: for i:=0 to 3 do begin if ((do_input_D2_ and (1 SHL i))<>0) then
      xor ebx,ebx
do_input_D2_m2:             mov ecx,ebx
         mov eax,$00000001
             shl eax,cl
             test eax,esi
             jz do_input_D2_m1
;//516: begin Rkbd_ext_a:=i;Rkbd_ext; r:=(r or Rkbd_ext_result);end;
	     mov [Rkbd_ext_a],ebx
             mov eax,edi
       call Rkbd_ext
     or ebp,[Rkbd_ext_result]
;//517: end;
do_input_D2_m1:     inc ebx
;//515: for i:=0 to 3 do begin if ((do_input_D2_ and (1 SHL i))<>0) then
            cmp ebx,$04
            jnz do_input_D2_m2
;//518: do_input_Result:= not ((r SHL 4) or (do_input_D2_ and $0F)) and $FF;
           shl ebp,$04
           and esi,$0f
             or ebp,esi
             not ebp
       and ebp,$000000ff
       mov [do_input_Result],ebp
;//520: end;
               pop ebp
               pop edi
              pop esi
               pop ebx
               ret
;====================================
do_input:; // работа со значениями портов in
;//563: do_input_port:=$C0+(do_input_port and $13);
     mov edx,[do_input_port]
           and edx,$13
     add edx,$000000c0
     mov [do_input_port],edx
;//564: case do_input_port of
     sub edx,$000000c2
             jz do_input_mc2
           sub edx,$0f
             jz  do_input_md1
               dec edx
             jz do_input_md2
             jmp do_input_melse
;//565: $C2:do_input_C2;
do_input_mc2:  call do_input_C2
              ret
;//566: $D1:do_input_D1;
do_input_md1:  call do_input_D1
               ret
;//567: $D2:do_input_D2
do_input_md2:   call do_input_D2
               ret
;//568: else begin do_input_Result:= $FF; end;
do_input_melse: mov [do_input_Result],$000000ff
;//571: end;
               ret
;====================================
fillcharVideoDirty:

               xor ebx,ebx
;uMain.pas.87: Rvideo_a:=c; Rvideo; WVideoDirty_a:=c;WVideoDirty_b:=(Rvideo_result xor ;l1);WVideoDirty;{$R+} end; end;
fillcharVideoDirty_m1:
       xor ecx,ecx
       mov cl,[videoM+ebx]
       mov eax,ecx
           xor eax,$01
mov [ebx+VideoDirtyM],al
              inc ebx
;uMain.pas.86: var c:Cardinal; begin {$R-} For c:=0 to 16384 do begin
     cmp ebx,$00004001
             jnz fillcharVideoDirty_m1
;uMain.pas.87: Rvideo_a:=c; Rvideo; ;WVideoDirty_a:=c;WVideoDirty_b:=(Rvideo_result ;;1);WVideoDirty;{$R+} end; end;
               ret
;====================================
    do_output_port rd 1
    do_output_bt rd 1
do_output:
;//599: begin
               push ebx
             mov ebx,eax
;//601: do_output_port:=$C0+(do_output_port and $13);
       mov eax,[do_output_port]
           and eax,$13
       add eax,$000000c0
       mov [do_output_port],eax
;//602: case do_output_port of
       mov eax,[do_output_port]
       sub eax,$000000c1
             jnz  do_output_m1
;//pas.604: fillcharVideoDirty;
             mov eax,ebx
       call fillcharVideoDirty
;//608: Wports_a:=do_output_port;Wports_b:=do_output_bt; Wports;
do_output_m1:
     mov eax,[do_output_port]
     mov edx,[do_output_bt]
     mov [eax+portsM],dl

;//610: end ;
               pop ebx
;pusha
;popa               
               ret
;==================================
    Wkbd_base_a rd 1
    Wkbd_base_b rd 1
Wkbd_base:
     mov eax,[Wkbd_base_a]
     mov edx,[Wkbd_base_b]
     mov [eax+kbd_baseM],dl
               ret
;=======================================
    Rkbd_base_a rd 1
    Rkbd_base_result rd 1 
Rkbd_base:
  Push ebx
mov edx,[Rkbd_base_a]
   xor ebx,ebx
   mov bl,[kbd_baseM+edx]
mov [Rkbd_base_result],ebx
   pop ebx
            ret
;===========================
    Rkbd_ext_a rd 1
    Rkbd_ext_result rd 1
Rkbd_ext:
  Push ebx
mov edx,[Rkbd_ext_a]
   xor ebx,ebx
   mov bl,[kbd_extM+edx]
mov [Rkbd_ext_result],ebx
   pop ebx
            ret
;===========================
    Wkbd_ext_a rd 1
    Wkbd_ext_b rd 1
Wkbd_ext:
     mov eax,[Wkbd_ext_a]
     mov edx,[Wkbd_ext_b]
     mov [eax+kbd_extM],dl
               ret
;=======================================

11

CONFIG.INC

Код:
__CPU_type fix p5 

MACROS.INC

Код:
@^ fix macro comment {
^@ fix }

; -------------------------
macro library [lname,fname]
{
  forward
    dd __#lname#_library_table__,__#lname#_library_name__
  common
    dd 0
  forward
    align 4
    __#lname#_library_name__ db fname,0
}

macro import lname,[name,sname]
{
  common
    align 4
    __#lname#_library_table__:
  forward
    if used name
      name dd __#name#_import_name__
    end if
  common
    dd 0
  forward
    if used name
      align 4
      __#name#_import_name__ db sname,0
    end if
}

macro export [name,sname]
{
  forward
    dd __#name#_export_name__,name
  common
    dd 0
  forward
    align 4
    __#name#_export_name__ db sname,0
}
; -------------------------

macro m2m dest,src {
 push src
 pop  dest
}


macro iglobal {
  IGlobals equ IGlobals,
  macro __IGlobalBlock { }
  
macro uglobal {
  UGlobals equ UGlobals,
  macro __UGlobalBlock { }

endg fix }      ; Use endg for ending iglobal and uglobal blocks.


macro IncludeIGlobals{
  macro IGlobals dummy,[n] \{ __IGlobalBlock
     purge __IGlobalBlock  \}
  match I, IGlobals \{ I \} }

macro IncludeUGlobals{
  macro UGlobals dummy,[n] \{
    \common
      \local begin, size
      begin = $
      virtual at $
    \forward
      __UGlobalBlock
      purge __UGlobalBlock
    \common
      size = $ - begin
    end virtual
    rb size
  \}
  match U, UGlobals \{ U \} }

uglobal
endg
  
iglobal
endg


; new application structure
macro meos_app_start
 {
  use32
  org 0x0

  db 'MENUET01'
  dd 0x01
  dd __start
  dd __end
  dd __memory
  dd __stack

  if used __params & ~defined __params
    dd __params
  else
    dd 0x0
  end if

  dd 0x0
 }
MEOS_APP_START fix meos_app_start

macro code
 {
  __start:
 }
CODE fix code

macro data
 {
  __data:
  IncludeIGlobals
 }
DATA fix data

macro udata
 {
  if used __params & ~defined __params
    __params:
      db 0
    __end:
      rb 255
  else
    __end:
  end if
  __udata:
  IncludeUGlobals
 }
UDATA fix udata

macro meos_app_end
 {
  align 32
  rb 2048
  __stack:
  __memory:
 }
MEOS_APP_END fix meos_app_end


; macro for defining multiline text data
struc mstr [sstring]
 {
  forward
    local ssize
    virtual at 0
      db sstring
      ssize = $
    end virtual
    dd ssize
    db sstring
  common
    dd -1
 }

; macro for defining multiline text data
struc mls [sstring]
 {
  forward
    local ssize
    virtual at 0
      db sstring  ; mod
      ssize = $
    end virtual
    db ssize
    db sstring
  common
    db -1         ; mod
 }



; strings
macro sz name,[data] {       ; from MFAR [mike.dld]
 common
  if used name
   name db data
   .size = $-name
  end if
}

macro szZ name,[data] {      ; same as sz, but with 0 at the end of line (ASCIIZ string) [dunkaist]
 common
  if used name
   name db data,0
   .size = $-name-1
  end if
}
sz0 fix szZ

macro lsz name,[lng,data] {  ; from MFAR [mike.dld]
 common
  if used name
   label name
 forward
  if lang eq lng
   db data
  end if
 common
   .size = $-name
  end if
}

macro szc name,elsz,[data] {         ; from MFAR [mike.dld]
 common
  local s,m
  m = 0
  if used name
   label name
 forward
   virtual at 0
    db data
    s = $
   end virtual
   d#elsz s
   if m < s
    m = s
   end if
   db data
 common
   .size = $-name
   .maxl = m
  end if
}

macro lszc name,elsz,[lng,data] {  ; from MFAR [mike.dld]
 common
  local s,m,c
  m = 0
  c = 0
  if used name
   label name
 forward
  if lang eq lng
   virtual at 0
    db data
    s = $
   end virtual
   d#elsz s
   if m < s
    m = s
   end if
   db data
   c = c+1
  end if
 common
   .size  = $-name
   .maxl  = m
   .count = c
  end if
}


; easy system call macro
macro mpack dest, hsrc, lsrc
{
  if (hsrc eqtype 0) & (lsrc eqtype 0)
    mov dest, (hsrc) shl 16 + lsrc
  else
    if (hsrc eqtype 0) & (~lsrc eqtype 0)
      mov dest, (hsrc) shl 16
      add dest, lsrc
    else
      mov dest, hsrc
      shl dest, 16
      add dest, lsrc
    end if
  end if
}

macro __mov reg,a,b {       ; mike.dld
 if (~a eq)&(~b eq)
   mpack reg,a,b
 else if (~a eq)&(b eq)
   mov reg,a
 end if
}


include 'config.inc'
;__CPU_type equ p5
SYSENTER_VAR    equ 0

macro mcall a,b,c,d,e,f {   ; mike.dld
 __mov eax,a
 __mov ebx,b
 __mov ecx,c
 __mov edx,d
 __mov esi,e
 __mov edi,f

   int 0x40
}


; -------------------------
macro header a,[b] {
 common
  use32
  org 0
  db 'MENUET',a
 forward
  if b eq
   dd 0
  else
   dd b
  end if }
macro section name { align 16
 label name }
macro func name {
 if ~used name
  display 'FUNC NOT USED: ',`name,13,10
 else
  align 4
  name:
  ;diff16 `name,0,name
;pushad
;pushfd
;dps `name
;newline
;mcall 5,1
;popfd
;popad
}
macro endf { end if }

macro diff16 title,l1,l2
 {
  local s,d
  s = l2-l1
  display title,': 0x'
  repeat 8
   d = '0' + s shr ((8-%) shl 2) and $0F
   if d > '9'
    d = d + 'A'-'9'-1
   end if
   display d
  end repeat
  display 13,10
 }

macro diff10 title,l1,l2
 {
  local s,d,z,m
  s = l2-l1
  z = 0
  m = 1000000000
  display title,': '
  repeat 10
   d = '0' + s / m
   s = s - (s/m)*m
   m = m / 10
   if d <> '0'
    z = 1
   end if
   if z <> 0
    display d
   end if
  end repeat
  display 13,10
 }

; optimize the code for size
__regs fix <eax,ebx,ecx,edx,esi,edi,ebp,esp>

macro add arg1,arg2
 {
   if (arg2 eqtype 0)
      if (arg2) = 1
     inc arg1
      else
     add arg1,arg2
      end if
   else
      add arg1,arg2
   end if
 }

macro sub arg1,arg2
 {
   if (arg2 eqtype 0)
      if (arg2) = 1
     dec arg1
      else
     sub arg1,arg2
      end if
   else
      sub arg1,arg2
   end if
 }

macro mov arg1,arg2
 {
   if (arg1 in __regs) & ((arg2 eqtype 0) | (arg2 eqtype '0'))
      if (arg2) = 0
     xor arg1,arg1
      else if (arg2) = 1
     xor arg1,arg1
     inc arg1
      else if (arg2) = -1
     or  arg1,-1
      else if (arg2) > -128 & (arg2) < 128
     push arg2
     pop  arg1
      else
     mov  arg1,arg2
      end if
   else
      mov arg1,arg2
   end if
 }


macro RGB [a] {
 common
  match (r=,g=,b),a \{
   \dd ((r) shl 16) or ((g) shl 8) or (b)
  \}
}


struc POINT _t,_dx,_dy {
 .x _t _dx
 .y _t _dy
}

; structure definition helper
include 'struct.inc'

struct RECT
  left   dd ?
  top    dd ?
  right  dd ?
  bottom dd ?
ends

struct BOX
  left   dd ?
  top    dd ?
  width  dd ?
  height dd ?
ends

; structures used in MeOS
struct process_information
  cpu_usage       dd ?  ; +0
  window_stack_position   dw ?  ; +4
  window_stack_value      dw ?  ; +6
              dw ?  ; +8
  process_name        rb 12 ; +10
  memory_start        dd ?  ; +22
  used_memory         dd ?  ; +26
  PID             dd ?  ; +30
  box             BOX   ; +34
  slot_state          dw ?  ; +50
              dw ?  ; +52
  client_box          BOX   ; +54
  wnd_state               db ?  ; +70
  rb (1024-71)
ends

struct system_colors
  frame        dd ?
  grab         dd ?
  grab_button      dd ?
  grab_button_text dd ?
  grab_text    dd ?
  work         dd ?
  work_button      dd ?
  work_button_text dd ?
  work_text    dd ?
  work_graph       dd ?
ends

struct FILEDATE
  Second db ?
  Minute db ?
  Hour   db ?
     db ?
  Day    db ?
  Month  db ?
  Year   dw ?
ends

struct FILEINFO
  Attributes dd ?
  IsUnicode  db ?
         db 3 dup(?)
  DateCreate FILEDATE
  DateAccess FILEDATE
  DateModify FILEDATE
  Size       dq ?
ends

; constants

; events
EV_IDLE        = 0
EV_TIMER       = 0
EV_REDRAW      = 1
EV_KEY         = 2
EV_BUTTON      = 3
EV_EXIT        = 4
EV_BACKGROUND  = 5
EV_MOUSE       = 6
EV_IPC         = 7
EV_STACK       = 8

; event mask bits for function 40
EVM_REDRAW     =    1b
EVM_KEY        =       10b
EVM_BUTTON     =      100b
EVM_EXIT       =     1000b
EVM_BACKGROUND =    10000b
EVM_MOUSE      =   100000b
EVM_IPC        =  1000000b
EVM_STACK      = 10000000b

STRUCT.INC

Код:
; Macroinstructions for defining data structures

macro struct name
 { fields@struct equ name
   match child parent, name \{ fields@struct equ child,fields@\#parent \}
   sub@struct equ
   struc db [val] \{ \common fields@struct equ fields@struct,.,db,<val> \}
   struc dw [val] \{ \common fields@struct equ fields@struct,.,dw,<val> \}
   struc du [val] \{ \common fields@struct equ fields@struct,.,du,<val> \}
   struc dd [val] \{ \common fields@struct equ fields@struct,.,dd,<val> \}
   struc dp [val] \{ \common fields@struct equ fields@struct,.,dp,<val> \}
   struc dq [val] \{ \common fields@struct equ fields@struct,.,dq,<val> \}
   struc dt [val] \{ \common fields@struct equ fields@struct,.,dt,<val> \}
   struc rb count \{ fields@struct equ fields@struct,.,db,count dup (?) \}
   struc rw count \{ fields@struct equ fields@struct,.,dw,count dup (?) \}
   struc rd count \{ fields@struct equ fields@struct,.,dd,count dup (?) \}
   struc rp count \{ fields@struct equ fields@struct,.,dp,count dup (?) \}
   struc rq count \{ fields@struct equ fields@struct,.,dq,count dup (?) \}
   struc rt count \{ fields@struct equ fields@struct,.,dt,count dup (?) \}
   macro db [val] \{ \common \local anonymous
         fields@struct equ fields@struct,anonymous,db,<val> \}
   macro dw [val] \{ \common \local anonymous
         fields@struct equ fields@struct,anonymous,dw,<val> \}
   macro du [val] \{ \common \local anonymous
         fields@struct equ fields@struct,anonymous,du,<val> \}
   macro dd [val] \{ \common \local anonymous
         fields@struct equ fields@struct,anonymous,dd,<val> \}
   macro dp [val] \{ \common \local anonymous
         fields@struct equ fields@struct,anonymous,dp,<val> \}
   macro dq [val] \{ \common \local anonymous
         fields@struct equ fields@struct,anonymous,dq,<val> \}
   macro dt [val] \{ \common \local anonymous
         fields@struct equ fields@struct,anonymous,dt,<val> \}
   macro rb count \{ \local anonymous
         fields@struct equ fields@struct,anonymous,db,count dup (?) \}
   macro rw count \{ \local anonymous
         fields@struct equ fields@struct,anonymous,dw,count dup (?) \}
   macro rd count \{ \local anonymous
         fields@struct equ fields@struct,anonymous,dd,count dup (?) \}
   macro rp count \{ \local anonymous
         fields@struct equ fields@struct,anonymous,dp,count dup (?) \}
   macro rq count \{ \local anonymous
         fields@struct equ fields@struct,anonymous,dq,count dup (?) \}
   macro rt count \{ \local anonymous
         fields@struct equ fields@struct,anonymous,dt,count dup (?) \}
   macro union \{ fields@struct equ fields@struct,,union,<
      sub@struct equ union \}
   macro struct \{ fields@struct equ fields@struct,,substruct,<
      sub@struct equ substruct \}
   virtual at 0 }

macro ends
 { match , sub@struct \{ restruc db,dw,du,dd,dp,dq,dt
    	 restruc rb,rw,rd,rp,rq,rt
    	 purge db,dw,du,dd,dp,dq,dt
    	 purge rb,rw,rd,rp,rq,rt
    	 purge union,struct
    	 match name=,fields,fields@struct \\{ fields@struct equ
            	      make@struct name,fields
            	      fields@\\#name equ fields \\}
    	 end virtual \}
   match any, sub@struct \{ fields@struct equ fields@struct> \}
   restore sub@struct }

macro make@struct name,[field,type,def]
 { common
    if $
     display 'Error: definition of ',`name,' contains illegal instructions.',0Dh,0Ah
     err
    end if
    local define
    define equ name
   forward
    local sub
    match , field \{ make@substruct type,name,sub def
         define equ define,.,sub, \}
    match any, field \{ define equ define,.#field,type,<def> \}
   common
    match fields, define \{ define@struct fields \} }

macro define@struct name,[field,type,def]
 { common
    local list
    list equ
   forward
    if ~ field eq .
     name#field type def
     sizeof.#name#field = $ - name#field
    else
     rb sizeof.#type
    end if
    local value
    match any, list \{ list equ list, \}
    list equ list <value>
   common
    sizeof.#name = $
    restruc name
    match values, list \{
    struc name value \\{
    match any, fields@struct \\\{ fields@struct equ fields@struct,.,name,<values> \\\}
    match , fields@struct \\\{ label .
   forward
     match , value \\\\{ field type def \\\\}
     match any, value \\\\{ field type value
    	   if ~ field eq .
    	    rb sizeof.#name#field - ($-field)
    	   end if \\\\}
   common \\\} \\} \} }

macro enable@substruct
 { macro make@substruct substruct,parent,name,[field,type,def]
    \{ \common
	\local define
	define equ parent,name
       \forward
	\local sub
	match , field \\{ match any, type \\\{ enable@substruct
        	       make@substruct type,name,sub def
        	       purge make@substruct
        	       define equ define,.,sub, \\\} \\}
	match any, field \\{ define equ define,.\#field,type,<def> \\}
       \common
	match fields, define \\{ define@\#substruct fields \\} \} }

enable@substruct

macro define@union parent,name,[field,type,def]
 { common
    virtual at 0
   forward
    if ~ field eq .
     virtual at 0
      parent#field type def
      sizeof.#parent#field = $ - parent#field
     end virtual
     if sizeof.#parent#field > $
      rb sizeof.#parent#field - $
     end if
    else if sizeof.#type > $
     rb sizeof.#type - $
    end if
   common
    sizeof.#name = $
    end virtual
    struc name [value] \{ \common
    label .\#name
    last@union equ
   forward
    match any, last@union \\{ virtual at .\#name
    	       field type def
    	      end virtual \\}
    match , last@union \\{ match , value \\\{ field type def \\\}
    	   match any, value \\\{ field type value \\\} \\}
    last@union equ field
   common rb sizeof.#name - ($ - .\#name) \} }

macro define@substruct parent,name,[field,type,def]
 { common
    virtual at 0
   forward
    if ~ field eq .
     parent#field type def
     sizeof.#parent#field = $ - parent#field
    else
     rb sizeof.#type
    end if
    local value
   common
    sizeof.#name = $
    end virtual
    struc name value \{
    label .\#name
   forward
     match , value \\{ field type def \\}
     match any, value \\{ field type value
    	  if ~ field eq .
    	   rb sizeof.#parent#field - ($-field)
    	  end if \\}
   common \} }

Emul.prt

Код:
; FASM Editor

include "Main.asm"

if 2 * 2 = 5
[options]
  countAsm=1
  countInc=0
[asm]
  asm1="Main.asm"
[inc]
end if

12

DELPHI\001\
Emul.dpr

Код:
program Emul;

uses
  Forms,
  Windows,
  uMain in 'uMain.pas' {MainForm};

{$R *.res}

begin
  SetThreadLocale(1049);
  Application.Initialize;
  Application.Title := 'ПК ЛЬВОВ';
  Application.CreateForm(TMainForm, MainForm);
  Application.Run;
end.

13

SOURCE_DELPHI\001\
uMain.pas part1

Код:
unit uMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Menus,MMSystem,ShellAPI, ImgList, ComCtrls,
  ToolWin;

type
  TserviceThread = Class (TThread)
    public
    procedure Execute; override;
    End;
    
  TMainForm = class(TForm)
    TimerMain: TTimer;
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    N4: TMenuItem;
    N5: TMenuItem;
    FullScreen1: TMenuItem;
    N6: TMenuItem;
    N17: TMenuItem;
    OpenDialogLvt: TOpenDialog;
    ResetCPU1: TMenuItem;
    N7: TMenuItem;
    N8: TMenuItem;
    N9: TMenuItem;
    N10: TMenuItem;
    N11: TMenuItem;
    N12: TMenuItem;
    N13: TMenuItem;
    N14: TMenuItem;
    N15: TMenuItem;
    Russian1: TMenuItem;
    English1: TMenuItem;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ImageList1: TImageList;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    ToolButton9: TToolButton;
    ToolButton10: TToolButton;
    ToolButton11: TToolButton;
    ToolButton12: TToolButton;
    ToolButton13: TToolButton;


    procedure TimerMainTimer(Sender: TObject);
    procedure do_write(addr : word; bt : byte);
    procedure i8080_init;
    procedure i8080_reset(addr: word);
    procedure invalid_opcode (opcode: byte);
    procedure putSound(bt : byte);
    function  do_read(addr : integer): word;
    procedure do_write2(a_lo : word; a_hi : word; bt : byte);
    function  do_read2(a_lo : word; a_hi : word): word;
    function  compute_color_index(port : byte; color : tcolor): tcolor;
    procedure WriteVRAM(b:Byte;x,y: integer);
    procedure init_memory();
    function  do_input(port : byte): byte;
    function  signal_inv_opc: boolean;
    procedure do_output(port : byte; bt : byte);
    procedure kbd(mask : word; press : boolean);
    procedure reset1;
    procedure load_bios;
    function  get_var(var1: word): word;
    procedure set_var(var1, val: word);
    procedure warm_start();
    procedure do_pause();
    procedure playTone();
    procedure enableSound();
    procedure i8080_do_opcodes(nb_cycles : integer);
    procedure draw_screen();
    procedure FirstPusk;
    function  readmask (keynum: word): word;
    procedure N4Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure FullScreen1Click(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure N17Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure NewLoadFile(filenameDnD: string;start : boolean);
    procedure ResetComp;
    procedure ResetCPU1Click(Sender: TObject);
    function  GrayTV(RGBColor : TColor) : TColor;
    procedure N7Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure N11Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure PlayBuffer(Buffer: array of byte);
    procedure N13Click(Sender: TObject);
    procedure VRAMTest(c1,b:Byte);
    procedure CalculateColor;
    procedure Russian1Click(Sender: TObject);
    procedure English1Click(Sender: TObject);
  private
    { Private declarations }
  public
    procedure WMDropFiles(var Msg: TMessage); message wm_DropFiles;
    { Public declarations }
  end;

var
  MainForm: TMainForm;

  ServiceThread: TServiceThread;
    r_A : INTEGER;   // регистрики
    r_B : INTEGER;
    r_C : INTEGER;
    r_D : INTEGER;
    r_E : INTEGER;
    r_H : INTEGER;
    r_L : INTEGER;
    r_F : INTEGER;
    r_PC : integer;  // адрес в памяти
    r_SP : integer;

    clock : integer;

    flags: array [0..256] of  word;

    f_S : byte;  // флаги
    f_Z : byte;
    f_5 : byte;
    f_A : byte;
    f_3 : byte;
    f_P : byte;
    f_1 : byte;
    f_C : byte;

    opcode : byte; // код текущей операции !!!

    halt_inv :byte;
    halt_opc :byte;
    halt_hlt :byte;
    halt_bpx :byte;
    halt_bpr :byte;
    halt_bpw :byte;
    halt_bpi :byte;
    halt_bpo :byte;

    FPusk: boolean; // первый запуск

    gamecanvas: tbitmap; // сюда все рисуем перед выводом на форму

    memory: array [0..65535] of byte;  // массив основной памяти $FFFF
    video : array [0..16384] of byte;  // видео память
    VideoDirty : array [0..16384] of word; //буфер для быстрой прорисовки
    ports : array [0..256]   of byte;      // порты
    bios  : array [0..65535] of byte;    // массив для загрузки биоса, можно сразу грузить но вдруг пригодися
    Myfile: array [0..90000] of byte; //файл может быть большим DUMP SAV который

    SuperColor: array[0..255, 0..255,1..4] of Tcolor; // еще один вариант по цвету

    pause : boolean; //пауза в эмуляторе
    FPS : integer;  // frames per second :-)

    speaker: array [0..2000] of word; //массивы для звуков
    speaked : word;
    soundData: array [0..2000] of BYTE;
    soundEnabled : boolean;
   { header : TWaveFormatEx;
    waveOut : hWaveOut;
    outHdr : TWaveHdr;
    pBuf : tHandle;
    pBuffer : pointer;}


    myfilelength: word; // длина скачаного файла
    //_filePos : integer;

    r_Halted: boolean;

    kbd_base : array  [0..8] of byte;  // массивы опроса клавиатуры
    kbd_ext : array  [0..4] of byte;

    BasicStack : word;    // переменные для бейсик программ
    BasicHotEntry : word;
    BasicProgBegin : word;
    BasicProgEnd : word;

    opcodes_to_run : integer;

    curSnd : word;
    restClock : word;

const MyColor:array[0..3] of Tcolor=(clBlack,clLime,clBlue,clRed);

implementation


{$R *.dfm}

procedure TMainForm.WMDropFiles(var Msg: TMessage);   // порцедура отвечает за принятие перетаскиваемого файла
var
FileName: array[0..256] of char;
begin
DragQueryFile(THandle(Msg.WParam), 0, FileName, SizeOf(Filename));
MainForm.Caption:=FileName;
NewLoadFile(FileName,true);
DragFinish(THandle(Msg.WParam));
end;

procedure TMainForm.do_write(addr : word; bt : byte); // если нужно будем записывать :-)
begin
  addr:=(addr and $FFFF);
  if (addr>=$C000) then
  begin
    exit;
  end;
  if ((ports[$C2] and 2)<>0) then
  begin
    memory[addr]:=bt;
  end
  else
     if (addr<$4000) then
       begin
         exit;
       end
       else
         if (addr<$8000) then
           begin
              video[addr-$4000]:=bt;
             // memory[addr]:=bt; // запишем еще и в память но не всегда
           end
           else
           begin
               memory[addr]:=bt;
           end;
end;



procedure TMainForm.i8080_init;
var
  j,i : word;
begin
  i:=0;
  while (i<256) do
  begin
    flags[i]:=f_1 or f_P;
    j:=0;
    while (j<8) do
    begin
       if ((i and (1 SHL j))<>0) then
             begin
                flags[i]:=(flags[i] xor f_P);
             end;
      inc(j);
    end;
       if ((i and $80)<>0) then
             begin
               flags[i]:=(flags[i] or f_S);
             end;
       if (i=0) then
             begin
               flags[i]:=(flags[i] or f_Z);
             end;
    inc(i);
  end;
end;

procedure TMainForm.i8080_reset(addr: word);
begin
  r_A:=0;
  r_F:=0;
  r_B:=0;
  r_C:=0;
  r_D:=0;
  r_E:=0;
  r_H:=0;
  r_L:=0;
  r_SP:=0;
  r_Halted:=false;
  clock:=0;
  r_PC:=addr;
end;

procedure TMainForm.invalid_opcode (opcode: byte); // а такое может возникнуть !!!???
begin
  ShowMessage('Нет такого кода у данного процессора '+inttostr(opcode)+' в '+inttostr(r_PC));
  inc(r_PC);
  r_PC:=r_PC and $ffff;
end;

procedure TMainForm.N11Click(Sender: TObject);
begin
n11.Checked:=not n11.Checked;
if n11.Checked then ToolButton3.ImageIndex:=8 else ToolButton3.ImageIndex:=7;
pause:=n11.Checked;
end;

procedure TMainForm.N13Click(Sender: TObject);
begin
N13.Checked:= not  N13.Checked;
end;

procedure TMainForm.N17Click(Sender: TObject);
begin
ShowMessage('Альфа 0.5');
end;


function TMainForm.do_read(addr : integer): word; // считаем значение из пямяти
begin
  addr:=(addr and $FFFF);
   if ((ports[$C2] and 2)<>0) then
  begin
    result := memory[addr];
  end
  else
  if (addr>$7FFF) then
  begin
    result := memory[addr];
  end
  else if (addr<$4000) then
  begin
    result := 0;
  end
  else begin
    result := video[addr-$4000];
  end;
end;

procedure TMainForm.do_write2(a_lo : word; a_hi : word; bt : byte);  // адреса
begin
  do_write(a_lo+(a_hi SHL 8),bt);
end;

function TMainForm.do_read2(a_lo : word; a_hi : word): word;
begin
  result := do_read(a_lo+(a_hi SHL 8));
end;

procedure TMainForm.init_memory();    // подготовим все к запуску
var
  j , i : integer;
begin
  i:=$0000;
  while (i<$10000) do
  begin
    memory[i]:=0;
    inc(i);
  end;
  i:=$0000;
  while (i<$4000) do begin
    video[i]:=0;
    inc(i);
  end;
  i:=$0000;
  while (i<$100) do begin
    ports[i]:=0;
    inc(i);
  end;
  i:=0;
  while (i<8) do begin
    kbd_base[i]:=0;
    inc(i);
  end;
  i:=0;
  while (i<4) do begin
    kbd_ext[i]:=0;
    inc(i);
  end;
  i:=0;
  while (i<256) do begin
    flags[i]:=(f_1 or f_P);
    j:=0;
    while (j<8) do begin
      if ((i and (1 shl j))<>0) then
      begin
        flags[i]:= (flags[i] xor f_P);
      end;
      inc(j);
    end;
    if ((i and $80)<>0) then
    begin
      flags[i]:= (flags[i] or f_S);
    end;

    if (i=0) then
    begin
      flags[i]:=(flags[i] or f_Z);
    end;
    inc(i);
  end;
end;


function TMainForm.do_input(port : byte): byte;  // работа со значениями портов in
var
  i,r : integer;
  nD2 ,nD0 : byte;
begin
  nD2:=0;
  nD0:=0;
  port:=$C0+(port and $13);
  case port of
  $C2:     begin result := ports[$C2]; end;
  $D1:     begin
             nD0:=not ports[$D0];
             r:=0;
             i:=0;
             while (i<8) do
             begin
              if ((nD0 and (1 SHL i))<>0) then
                 begin
                    r:=(r or kbd_base[i]);
                 end;
              inc(i);
             end;
             result :=  ((not r) and $FF);
           end;
   $D2:    begin
             nD2:= not ports[$D2];
             r:=0;
             i:=0;
             while (i<4) do
              begin
               if ((nD2 and (1 SHL i))<>0) then
                  begin
                   r:=(r or kbd_ext[i]);
                  end;
               inc(i);
              end;
              result := not ((r SHL 4) or (nD2 and $0F)) and $FF;
            end
     else
        begin
           result := $FF;
        end;
end;
end;

procedure TMainForm.do_output(port : byte; bt : byte); // out
begin
  port:=$C0+(port and $13);
  case port of
  $c1:  begin // изменение порта цвета
          fillchar(VideoDirty,sizeof(VideoDirty),257); // чистим массив
        end;
  $c2:  begin
          putSound(bt);  // вот тут получаем звук
        end;
  end;
  ports[port]:=bt;
end ;

function TMainForm.signal_inv_opc: boolean;
  begin
      result :=false;
  end;

procedure TMainForm.kbd(mask : word; press : boolean); //  по маске вкл выкл клавишу
var
  brow : byte;
  erow : byte;
  bcol : byte;
  ecol : byte;
begin
  bcol:=(mask SHR 12) and $0F;
  brow:=(mask SHR 8) and $0F;
  ecol:=(mask SHR 4) and $0F;
  erow:=(mask SHR 0) and $0F;
  
  if ((brow<8) and (bcol<8)) then
  begin
   if (press) then
    begin
      kbd_base[bcol]:=(kbd_base[bcol] or (1 SHL brow));
    end else begin
      kbd_base[bcol]:= (kbd_base[bcol] and (not(1 SHL brow)));
    end;
  end;

  if ((erow<8) and (ecol<4)) then
  begin
    if (press) then
    begin
      kbd_ext[ecol]:= (kbd_ext[ecol]or (1 SHL erow));
    end else begin
      kbd_ext[ecol]:= (kbd_ext[ecol] and (not(1 SHL erow)));
    end;
  end;
end;

procedure TMainForm.reset1;    // полный ресет :)
var
  i : word;
begin
  i:=0;
  while (i<256) do begin
    ports[i]:=$FF;
    inc(i);
  end;
  i8080_init;
end;

procedure TMainForm.load_bios;    // загрузка биоса из файла
var
i: word;
b: byte;
f: file of byte;
begin
  i:=0;
  AssignFile(F,ExtractFilePath(Application.ExeName)+'\bios.dat');
  Reset(F);                   // проверять заголовок не будем :)
  while not eof(f) do
   begin
    read(F,b);
    bios[i]:=b; // загрузим в массив , а вдруг пригодится
    inc(i);
   end;
  closeFile(F);
  i:=0;
  while (i<$4000) do begin
    memory[$C000+i]:=bios[22+i];
    inc(i);
  end;
end;


procedure TMainForm.N2Click(Sender: TObject);
begin
  OpenDialogLvt.InitialDir:=ExtractFilePath(Application.ExeName);
  if OpenDialogLvt.Execute then NewLoadFile(OpenDialogLvt.FileName,true);
end;

procedure TMainForm.N4Click(Sender: TObject);
begin
gamecanvas.Free;
close;
end;

procedure TMainForm.N7Click(Sender: TObject);   // влючим ЧБ телевизор
begin
N7.Checked:= not N7.Checked;
if N7.Checked then
     ToolButton7.ImageIndex:=13 else
     ToolButton7.ImageIndex:=12;

fillchar(VideoDirty,sizeof(VideoDirty),257);
draw_screen;
end;

function TMainForm.get_var(var1: word): word;  // чтение и запись нужных значений из пямяти
begin
    result:= memory[var1] + memory[var1+1]*256;
end;

procedure TMainForm.set_var(var1, val: word);
begin
    memory[var1]:= (val and $FF);
    memory[var1+1]:= (round(val/256) and $FF);
end;

procedure TMainForm.warm_start();  // горячий запуск
begin
  ports[$C2]:=$FF;
  r_SP:=BasicStack;
  set_var(BasicStack,BasicHotEntry);
  r_PC:=BasicHotEntry;
end;

procedure TMainForm.NewLoadFile(filenameDnD: string; start : boolean);  //процедура загрузки всех видов файлов
var
f:file of byte;
b:Byte;
s: string;
posBas, Xend ,Xbeg ,Xrun : word;
i: integer;
begin
  s:='';
      AssignFile(f,filenameDnD); // распознаем что за файл
      Reset(f);
      for I:= 0 to 8  do
        begin
           read(f,b);
           s:=s+chr(b);
           //Myfile[j]:=strtoint(s);
           // Size(f);
           //seek(f,100);
        end;
      if s='LVOV/2.0/' then // стандартный LVT файл
      begin
         read(f,b);
         if b=$D0 then      // это бинарник
         begin
           seek(F,0); // вернемся к началу файла
           i:=0;
           while not eof(f) do
              begin
                read(F,b);
                Myfile[i]:=b;
                inc(i);
              end;
           myfilelength:=i;
           closeFile(F);     //закрываем файл
           Xbeg:=Myfile[16]+Myfile[17]*256;
           Xend:=Myfile[18]+Myfile[19]*256;
           Xrun:=Myfile[20]+Myfile[21]*256;
           if (start) then
              begin
                warm_start();
                r_PC:=Xrun;
              end;
           i:=0;
           while (i<=Xend-Xbeg) do
              begin
               do_write(Xbeg+i,Myfile[i+22]);
               inc(i);
              end;
         end
         else
         begin      //это бeйсик (надеюсь больше ничего нет :-) )
           seek(F,0); // вернемся к началу файла
           i:=0;
           while not eof(f) do
              begin
                read(F,b);
                Myfile[i]:=b;
                inc(i);
              end;
            myfilelength:=i-1;
            warm_start();
            posBas:=get_var(BasicProgBegin);
            i:=0;
            while (i<myfilelength-16) do
               begin
                do_write(posBas+i,Myfile[i+16]);
                inc(i);
               end;
              set_var(BasicProgEnd,posBas+myfilelength-16);
              // направим RUN
              MainForm.SetFocus;

              //i8080_do_opcodes(opcodes_to_run);


              //KeyboardForm.SendKeys('RUN');
         end;
       end;
      if s='LVOV/DUMP' then // стандартный SAV файл дампа эмулятор Калашникова
         begin
           seek(F,0); // вернемся к началу файла
           i:=0;
           while not eof(f) do
              begin
                read(F,b);
                Myfile[i]:=b;
                inc(i);
              end;
           i:=0;
           closeFile(F);
           while (i<$10000) do
           begin
             memory[i]:=Myfile[17+i];
             inc(i);
           end;
           i:=0;
           while (i<$4000) do
           begin
            video[i]:=Myfile[17+$10000+i];
            inc(i);
           end;
           i:=0;
           while (i<$100) do
           begin
            ports[i]:=Myfile[17+$10000+$4000+i];
            inc(i);
           end;
           r_B:=Myfile[17+$10000+$4000+$100];
           r_H:=Myfile[17+$10000+$4000+$100+4];
           r_C:=Myfile[17+$10000+$4000+$100+1];
           r_L:=Myfile[17+$10000+$4000+$100+5];
           r_D:=Myfile[17+$10000+$4000+$100+2];
           r_A:=Myfile[17+$10000+$4000+$100+6];
           r_E:=Myfile[17+$10000+$4000+$100+3];
           r_F:=Myfile[17+$10000+$4000+$100+7];
           r_SP:=Myfile[17+$10000+$4000+$100+9]*256+Myfile[17+$10000+$4000+$100+8];
           r_PC:=Myfile[17+$10000+$4000+$100+11]*256+Myfile[17+$10000+$4000+$100+10];
           fillchar(VideoDirty,sizeof(VideoDirty),257); // чистим массив
           draw_screen;
         end;
end;

procedure  TMainForm.do_pause();
begin
	pause := not pause;
end;

procedure TMainForm.i8080_do_opcodes(nb_cycles : integer);    //выполнение комманд процессора
var
  tmp  : integer;
  tmp3 : integer;
  tmp2 : integer;
  tmp1 : integer;
  opcode : integer;
begin
  clock:=0; tmp1:=0;  tmp2:=0;  tmp3:=0;  tmp:=0;     //бнулим :-) 
 while (clock < nb_cycles) do
 begin
  tmp:=r_PC;
  opcode:=do_read(r_PC);
 if (r_PC=56724) then       //программа хочет прочитать еще файл
                 begin
                    //Myfile:=addfile[fileCounter];
                    //inc(fileCounter);
                    ///_filePos:=0;
                     pause:=true;
                     N2Click(Self);
                     if OpenDialogLvt.Execute then NewLoadFile(OpenDialogLvt.FileName,true);
                     pause:=false;
                 end ;
                { else
                 begin
                     if (r_PC=58576) then
                          begin
                            opcode:=$C9;
                          end;
                     if (r_PC=58558) then
                          begin
                             if (_filePos<10) then
                                 begin
                                   r_A:=208;
                                   inc(_filePos);
                                 end
                                 else
                                 if (_filePos<16) then
                                       begin
                                          r_A:=do_read(48780+_filePos-10);
                                          inc(_filePos);
                                       end
                                       else
                                       if (_filePos<myfilelength) then
                                                  begin
                                                    r_A:=Myfile[_filePos];
                                                    inc(_filePos);
                                                  end
                                                  else
                                                  begin
                                                    r_A:=$FF;
                                                  end;
                            opcode:=$C9;
                            end;
                    if (r_PC=56778) then
                              begin
                                 if (_filePos<Myfilelength-1) then
                                        begin
                                           r_L:=Myfile[_filePos];
                                           inc(_filePos);
                                           r_H:=Myfile[_filePos];
                                           inc(_filePos);
                                        end
                                        else
                                        begin
                                          r_L:=$FF;
                                          r_H:=$FF;
                                        end;
                               opcode:=$C9;
                               end;
                     {if (gamover_point=r_PC) then
                         begin
                           makeRequest();
                         end;  }
               { end;  }

case opcode of         // анализируем текущий код 00 .. FF, меняем значение clock в зависимоти от "длинны" команды ...
                       // прыгаем по памяти, меняем значения регистров и портов  ПРОЦ РАБОТАЕТ !!!!
  $00:
  begin
    clock:=clock+4;
    r_PC:=r_PC+1;
  end;
  $F3:
  begin
    clock:=clock+4;
    r_PC:=r_PC+1;
  end;
  $FB:
  begin
    clock:=clock+4;
    r_PC:=r_PC+1;
  end;

  $01:
  begin
    r_B:=do_read(r_PC+2);
    r_C:=do_read(r_PC+1);
    clock:=clock+10;
    r_PC:=r_PC+3;
  end;
  
  $02: 
  begin
    do_write2(r_C,r_B,r_A);
    clock:=clock+7;
    r_PC:=r_PC+1;
  end;
  
  $03: 
  begin
    r_C:=r_C+1;
    if (r_C>$FF) then
    begin
      r_C:=0;
      r_B:=r_B+1;
      if (r_B>$FF) then
      begin
        r_B:=0;
      end;
    end;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;

  $04:
  begin
    tmp2:=((r_B+1) and $FF);
    r_F:=(flags[tmp2] or (r_F and f_C));
    if (((tmp2 xor r_B) and $10)<>0) then
    begin
      r_F:=r_F or f_A;
    end;
    r_B:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $05: 
  begin
    tmp2:=((r_B-1) and $FF);
    r_F:=(flags[tmp2] or (r_F and f_C));

    if (((tmp2 xor r_B) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_B:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $06: 
  begin
    r_B:=do_read(r_PC+1);
    clock:=clock+7;
    r_PC:=r_PC+2;
  end;
  
  $07: 
  begin
    r_A:=r_A SHL 1;
    if (r_A>$FF) then
    begin
      r_A:=r_A or 1;
      r_F:=r_F or f_C;
      r_A:= r_A and $FF;
    end
    else
    begin
      r_F:=(r_F and  (not f_C));
    end;
    clock:=clock+4;
    r_PC:=r_PC+1;
  end;
  $08:  begin     if (signal_inv_opc()) then
           begin
           end
           else
           begin
           clock:=clock+4;
           r_PC:=r_PC+1;
           end; end;
  $10:  begin     if (signal_inv_opc()) then
           begin
           end
           else
           begin
           clock:=clock+4;
           r_PC:=r_PC+1;
           end; end;
  $18:  begin     if (signal_inv_opc()) then
           begin
           end
           else
           begin
           clock:=clock+4;
           r_PC:=r_PC+1;
           end; end;
  $20:  begin     if (signal_inv_opc()) then
           begin
           end
           else
           begin
           clock:=clock+4;
           r_PC:=r_PC+1;
           end; end;
  $28:  begin     if (signal_inv_opc()) then
           begin
           end
           else
           begin
           clock:=clock+4;
           r_PC:=r_PC+1;
           end; end;
  $30:  begin     if (signal_inv_opc()) then
           begin
           end
           else
           begin
           clock:=clock+4;
           r_PC:=r_PC+1;
           end; end;
  $38:
  begin
    if (signal_inv_opc()) then
           begin
           end
           else
           begin
           clock:=clock+4;
           r_PC:=r_PC+1;
           end;
  end;
  
  $09: 
  begin
    r_L:=r_L+r_C;
    r_H:=r_H+r_B;
    if (r_L>$FF) then
    begin
      inc(r_H);
      r_L:=(r_L and $FF);
    end;
    if (r_H>$FF) then
    begin
      r_H:=(r_H and $FF);
      r_F:=(r_F or f_C);
    end
    else
    begin
      r_F:=(r_F and (not f_C));
    end;
    clock:=clock+10;
    r_PC:=r_PC+1;
  end;
  
  $0A: 
  begin
    r_A:=do_read2(r_C,r_B);
    clock:=clock+7;
    r_PC:=r_PC+1;
  end;

  $0B: 
  begin
    r_C:=r_C-1;
    if (r_C<0) then
    begin
      r_C:=$FF;
      r_B:=r_B-1;
      if (r_B<0) then
      begin
        r_B:=$FF;
      end;
    end;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $0C: 
  begin
    tmp2:=((r_C+1) and $FF);
    r_F:=(flags[tmp2] or (r_F and f_C));
    if (((tmp2 xor r_C) and $10)<>0) then
    begin
      r_F:=r_F or f_A;
    end;
    r_C:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;

  $0D:
  begin
    tmp2:=((r_C-1) and $FF);
    r_F:=flags[tmp2] or (r_F and f_C);

    if (((tmp2 xor r_C) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_C:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $0E: 
  begin
    r_C:=do_read(r_PC+1);
    clock:=clock+7;
    r_PC:=r_PC+2;
  end;
  
  $0F: 
  begin
    tmp1:=(r_A and 1);
    r_A:=(r_A shr 1);
    if (tmp1<>0) then
    begin
      r_A:=(r_A or $80);
      r_F:=(r_F or f_C);
    end
    else
    begin
      r_F:=(r_F and ( not f_C));
    end;
    clock:=clock+4;
    r_PC:=r_PC+1;
  end;
  
  $11: 
  begin
    r_D:=do_read(r_PC+2);
    r_E:=do_read(r_PC+1);
    clock:=clock+10;
    r_PC:=r_PC+3;
  end;
  
  $12: 
  begin
    do_write2(r_E,r_D,r_A);
    clock:=clock+7;
    r_PC:=r_PC+1;
  end;
  
  $13: 
  begin
    r_E:=r_E+1;
    if (r_E>$FF) then
    begin
      r_E:=0;
      r_D:=r_D+1;
      if (r_D>$FF) then
      begin
        r_D:=0;
      end;
    end;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $14: 
  begin
    tmp2:=((r_D+1)and $FF);
    r_F:=(flags[tmp2] or (r_F and f_C));
    
    if (((tmp2 xor r_D) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_D:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $15: 
  begin
    tmp2:=((r_D-1)and $FF);
    r_F:=(flags[tmp2] or (r_F and f_C));
    
    if (((tmp2 xor r_D) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_D:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $16: 
  begin
    r_D:=do_read(r_PC+1);
    clock:=clock+7;
    r_PC:=r_PC+2;
  end;
  
  $17: 
  begin
    r_A:=(r_A shl 1);

    if ((r_F and f_C)<>0) then 
    begin
      r_A:=(r_A or 1);
    end;
    
    if (r_A>$FF) then 
    begin
      r_F:=(r_F or f_C);
      r_A:=(r_A and $FF);
    end else begin
      r_F:=(r_F and (not f_C));
    end;
    clock:=clock+4;
    r_PC:=r_PC+1;
  end;
  
  $19: 
  begin
    r_L:=(r_L + r_E);
    r_H:=(r_H + r_D);
    
    if (r_L>$FF) then 
    begin
      inc(r_H);
      r_L:=(r_L and $FF);
    end;

    if (r_H>$FF) then 
    begin
      r_H:=(r_H and $FF);
      r_F:=(r_F or f_C);
    end
    else
    begin
      r_F:=(r_F and not (f_C));
    end;
    clock:=clock+10;
    r_PC:=r_PC+1;
  end;
  
  $1A: 
  begin
    r_A:=do_read2(r_E,r_D);
    clock:=clock+7;
    r_PC:=r_PC+1;
  end;
  
  $1B: 
  begin
    r_E:=r_E-1;
    if (r_E<0) then
    begin
      r_E:=$FF;
      r_D:=r_D-1;
      if (r_D<0) then
      begin
        r_D:=$FF;
      end;
    end;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $1C: 
  begin
    tmp2:=((r_E+1)and $FF);
    r_F:=(flags[tmp2] or (r_F and f_C));

    if (((tmp2 xor r_E) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_E:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $1D: 
  begin
    tmp2:=((r_E-1) and $FF);
    r_F:=(flags[tmp2] or (r_F and f_C));

    if (((tmp2 xor r_E) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_E:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $1E: 
  begin
    r_E:=do_read(r_PC+1);
    clock:=clock+7;
    r_PC:=r_PC+2;
  end;
  
  $1F: 
  begin
    tmp1:=(r_A and 1);
    r_A:=(r_A SHR 1);
    
    if ((r_F and f_C)<>0) then
    begin
      r_A:=(r_A or $80);
    end;

    if (tmp1<>0) then
    begin
      r_F:=(r_F or f_C);
    end
    else
    begin
      r_F:=(r_F and not(f_C));
    end;
    clock:=clock+4;
    r_PC:=r_PC+1;
  end;

  $21:
  begin
    r_H:=do_read(r_PC+2);
    r_L:=do_read(r_PC+1);
    clock:=clock+10;
    r_PC:=r_PC+3;
  end;

  $22: 
  begin
    tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
    do_write(tmp1,r_L);
    do_write(tmp1+1,r_H);
    clock:=clock+16;
    r_PC:=r_PC+3;
  end;
  
  $23: 
  begin
    r_L:=r_L+1;
    if (r_L>$FF) then
    begin
      r_L:=0;
      r_H:=r_H+1;
      if (r_H>$FF) then
      begin
        r_H:=0;
      end;
    end;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $24: 
  begin
    tmp2:=((r_H+1) and $FF);
    r_F:=(flags[tmp2] or (r_F and f_C));
    if (((tmp2 xor r_H) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_H:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $25: 
  begin
    tmp2:=((r_H-1) and $FF);
    r_F:=(flags[tmp2] or (r_F and f_C));
    if (((tmp2 xor r_H) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_H:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $26: 
  begin
    r_H:=do_read(r_PC+1);
    clock:=clock+7;
    r_PC:=r_PC+2;
  end;
  
  $27: 
  begin
    tmp1:=0;
    if (((r_F and f_C)<>0) or  (r_A>$99)) then
    begin
      tmp1:=(tmp1 or $60);
    end;
    if (((r_F and f_A)<>0)    or  ((r_A and $0F)>$09)) then
    begin
      tmp1:=(tmp1 or $06);
    end;
    tmp2:=r_A+tmp1;
    r_F:=flags[tmp2 and $FF];
    if (((tmp2 xor r_A xor tmp1) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    if (tmp2>$FF) then
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+4;
    r_PC:=r_PC+1;
  end;
  
  $29: 
  begin
    r_L:=r_L + r_L;
    r_H:=r_H + r_H;
    
    if (r_L>$FF) then 
    begin
      inc(r_H);
      r_L:=(r_L and $FF);
    end;
    if (r_H>$FF) then
    begin
      r_H:=(r_H and $FF);
      r_F:=(r_F or f_C);
    end else begin
      r_F:=(r_F and (not f_C));
    end;
    clock:=clock+10;
    r_PC:=r_PC+1;
  end;
  
  $2A: 
  begin
    tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
    r_L:=do_read(tmp1);
    r_H:=do_read(tmp1+1);
    clock:=clock+16;
    r_PC:=r_PC+3;
  end;
  
  $2B: 
  begin
    r_L:=r_L-1;
    if (r_L <0) then
    begin
      r_L:=$FF;
      r_H:=r_H-1;
      if (r_H<0) then
      begin
        r_H:=$FF;
      end;
    end;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $2C: 
  begin
    tmp2:=((r_L+1) and $FF);
    r_F:=(flags[tmp2] or (r_F and f_C));
    if (((tmp2 xor r_L) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_L:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $2D: 
  begin
    tmp2:=((r_L-1) and $FF);
    r_F:=(flags[tmp2] or (r_F and f_C));
    if (((tmp2 xor r_L) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_L:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $2E: 
  begin
    r_L:=do_read(r_PC+1);
    clock:=clock+7;
    r_PC:=r_PC+2;
  end;
  
  $2F: 
  begin
    r_A:=(r_A xor $FF);
    clock:=clock+4;
    r_PC:=r_PC+1;
  end;
  
  $31: 
  begin
    r_SP:=(do_read(r_PC+2) shl 8)+do_read(r_PC+1);
    clock:=clock+10;
    r_PC:=r_PC+3;
  end;
  
  $32: 
  begin
    do_write2(do_read(r_PC+1),do_read(r_PC+2),r_A);
    clock:=clock+13;
    r_PC:=r_PC+3;
  end;
  
  $33: 
  begin
    if (r_SP=$FFFF) then
    begin
      r_SP:=0;
    end
    else
    begin
      inc(r_SP);
    end;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $34: 
  begin
    tmp1:=do_read2(r_L,r_H);
    tmp2:=((tmp1+1)  and $FF);
    r_F:=(flags[tmp2] or (r_F  and f_C));
    if (((tmp2 xor tmp1) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    do_write2(r_L,r_H,tmp2);
    clock:=clock+10;
    r_PC:=r_PC+1;
  end;
  
  $35: 
  begin
    tmp1:=do_read2(r_L,r_H);
    tmp2:=((tmp1-1) and $FF);
    r_F:=flags[tmp2] or (r_F and f_C);
    if (((tmp2 xor tmp1) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    do_write2(r_L,r_H,tmp2);
    clock:=clock+10;
    r_PC:=r_PC+1;
  end;

  $36:
  begin
    do_write2(r_L,r_H,do_read(r_PC+1));
    clock:=clock+10;
    r_PC:=r_PC+2;
  end;

  $37:
  begin
    r_F:=(r_F or f_C);
    clock:=clock+4;
    r_PC:=r_PC+1;
  end;
  
  $39: 
  begin
    r_L:=(r_L + (r_SP and $FF));
    r_H:=(r_H + ((r_SP shr 8) and $FF));
    if (r_L>$FF) then
    begin
      inc(r_H);
      r_L:=(r_L and $FF);
    end;
    if (r_H>$FF) then 
    begin
      r_H:=(r_H and $FF);
      r_F:=(r_F or f_C);
    end else begin
      r_F:=(r_F and (not f_C));
    end;
    clock:=clock+10;
    r_PC:=r_PC+1;
  end;
  
  $3A: 
  begin
    r_A:=do_read2(do_read(r_PC+1),do_read(r_PC+2));
    clock:=clock+13;
    r_PC:=r_PC+3;
  end;
  
  $3B: 
  begin
    if (r_SP<>0) then 
    begin
      r_SP:=r_SP-1;
    end
    else
    begin
      r_SP:=$FFFF;
    end;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $3C: 
  begin
    tmp2:=((r_A+1) and $FF);
    r_F:=(flags[tmp2] or (r_F and f_C));
    if (((tmp2 xor r_A) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;

  $3D:
  begin
    tmp2:=((r_A-1) and $FF);
    r_F:=(flags[tmp2] or (r_F and f_C));
    if (((tmp2 xor r_A) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $3E: 
  begin
    r_A:=do_read(r_PC+1);
    clock:=clock+7;
    r_PC:=r_PC+2;
    
  end;
  
  $3F: 
  begin
    r_F:=r_F xor f_C;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $40:  begin clock:=clock+5;    r_PC:=r_PC+1; end;
  $49:  begin clock:=clock+5;    r_PC:=r_PC+1; end;
  $52:  begin clock:=clock+5;    r_PC:=r_PC+1; end;
  $5B:  begin clock:=clock+5;    r_PC:=r_PC+1; end;
  $64:  begin clock:=clock+5;    r_PC:=r_PC+1; end;
  $6D:  begin clock:=clock+5;    r_PC:=r_PC+1; end;
  $7F:
  begin
    clock:=clock+5;    r_PC:=r_PC+1;
  end;

  $41:
  begin
    r_B:=r_C;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;

  $42:
  begin
    r_B:=r_D;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $43: 
  begin
    r_B:=r_E;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $44: 
  begin
    r_B:=r_H;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $45: 
  begin
    r_B:=r_L;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $46: 
  begin
    r_B:=do_read2(r_L,r_H);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $47: 
  begin
    r_B:=r_A;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $48: 
  begin
    r_C:=r_B;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $4A: 
  begin
    r_C:=r_D;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $4B: 
  begin
    r_C:=r_E;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $4C: 
  begin
    r_C:=r_H;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $4D: 
  begin
    r_C:=r_L;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $4E: 
  begin
    r_C:=do_read2(r_L,r_H);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $4F: 
  begin
    r_C:=r_A;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $50: 
  begin
    r_D:=r_B;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $51: 
  begin
    r_D:=r_C;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $53: 
  begin
    r_D:=r_E;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $54: 
  begin
    r_D:=r_H;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $55: 
  begin
    r_D:=r_L;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $56: 
  begin
    r_D:=do_read2(r_L,r_H);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $57: 
  begin
    r_D:=r_A;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $58: 
  begin
    r_E:=r_B;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $59: 
  begin
    r_E:=r_C;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $5A: 
  begin
    r_E:=r_D;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $5C: 
  begin
    r_E:=r_H;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $5D: 
  begin
    r_E:=r_L;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $5E: 
  begin
    r_E:=do_read2(r_L,r_H);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $5F: 
  begin
    r_E:=r_A;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $60: 
  begin
    r_H:=r_B;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $61: 
  begin
    r_H:=r_C;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $62: 
  begin
    r_H:=r_D;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $63: 
  begin
    r_H:=r_E;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $65: 
  begin
    r_H:=r_L;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $66: 
  begin
    r_H:=do_read2(r_L,r_H);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $67: 
  begin
    r_H:=r_A;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $68: 
  begin
    r_L:=r_B;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $69: 
  begin
    r_L:=r_C;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $6A: 
  begin
    r_L:=r_D;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $6B: 
  begin
    r_L:=r_E;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $6C: 
  begin
    r_L:=r_H;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $6E: 
  begin
    r_L:=do_read2(r_L,r_H);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $6F: 
  begin
    r_L:=r_A;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $70: 
  begin
    do_write2(r_L,r_H,r_B);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $71: 
  begin
    do_write2(r_L,r_H,r_C);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $72: 
  begin
    do_write2(r_L,r_H,r_D);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $73: 
  begin
    do_write2(r_L,r_H,r_E);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $74: 
  begin
    do_write2(r_L,r_H,r_H);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $75: 
  begin
    do_write2(r_L,r_H,r_L);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $76: 
  begin
   // cpu_halt_state:=true;
   // cpu_halt_reason:=halt_hlt;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $77: 
  begin
    do_write2(r_L,r_H,r_A);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $78: 
  begin
    r_A:=r_B;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $79: 
  begin
    r_A:=r_C;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $7A: 
  begin
    r_A:=r_D;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $7B: 
  begin
    r_A:=r_E;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $7C: 
  begin
    r_A:=r_H;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $7D: 
  begin
    r_A:=r_L;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $7E: 
  begin
    r_A:=do_read2(r_L,r_H);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $80: 
  begin
    tmp2:=r_A+r_B;
    r_F:=flags[tmp2 and $FF];
    
    if (((tmp2  xor r_A  xor r_B) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=(tmp2 and $FF);
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $81: 
  begin
    tmp2:=r_A+r_C;
    r_F:=flags[tmp2 and $FF];
    
    if (((tmp2  xor r_A  xor r_C) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $82: 
  begin
    tmp2:=r_A+r_D;
    r_F:=flags[tmp2 and $FF];
    
    if (((tmp2  xor r_A  xor r_D) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $83: 
  begin
    tmp2:=r_A+r_E;
    r_F:=flags[tmp2 and $FF];
    
    if (((tmp2  xor r_A  xor r_E) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $84: 
  begin
    tmp2:=r_A+r_H;
    r_F:=flags[tmp2 and $FF];
    
    if (((tmp2  xor r_A  xor r_H) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $85: 
  begin
    tmp2:=r_A+r_L;
    r_F:=flags[tmp2 and $FF];
    
    if (((tmp2  xor r_A  xor r_L) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $86: 
  begin
    tmp1:=do_read2(r_L,r_H);
    tmp2:=r_A+tmp1;
    r_F:=flags[tmp2 and $FF];
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $87: 
  begin
    tmp2:=r_A+r_A;
    r_F:=flags[tmp2 and $FF];
    
    if (((tmp2  xor r_A  xor r_A) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $88: 
  begin
    tmp2:=r_A+r_B;
    if ((r_F and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
    r_F:=flags[tmp2 and $FF];
    
    if (((tmp2  xor r_A  xor r_B) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $89: 
  begin
    tmp2:=r_A+r_C;
    if ((r_F and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
    r_F:=flags[tmp2 and $FF];
    
    if (((tmp2  xor r_A  xor r_C) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $8A: 
  begin
    tmp2:=r_A+r_D;
    if ((r_F and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
    r_F:=flags[tmp2 and $FF];
    
    if (((tmp2  xor r_A  xor r_D) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $8B: 
  begin
    tmp2:=r_A+r_E;
    if ((r_F and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
    r_F:=flags[tmp2 and $FF];
    
    if (((tmp2  xor r_A  xor r_E) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $8C: 
  begin
    tmp2:=r_A+r_H;
    if ((r_F and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
    r_F:=flags[tmp2 and $FF];
    
    if (((tmp2  xor r_A  xor r_H) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=r_F or f_C;
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $8D: 
  begin
    tmp2:=r_A+r_L;
    if ((r_F and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
    r_F:=flags[tmp2 and $FF];
    
    if (((tmp2  xor r_A  xor r_L) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $8E: 
  begin
    tmp1:=do_read2(r_L,r_H);
    tmp2:=r_A+tmp1;
    if ((r_F and f_C)<>0) then  tmp2:=tmp2+1 else tmp2:=tmp2+0;
    r_F:=flags[tmp2 and $FF];
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $8F: 
  begin
    tmp2:=r_A+r_A;
    if ((r_F and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
    r_F:=flags[tmp2 and $FF];

    if (((tmp2  xor r_A  xor r_A) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;

    if (tmp2>$FF) then
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $90: 
  begin
    tmp2:=(r_A-r_B) and $FF;
    r_F:=flags[tmp2];

    if (r_A<r_B) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_B) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $91: 
  begin
    tmp2:=(r_A-r_C) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<r_C) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_C) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $92: 
  begin
    tmp2:=(r_A-r_D) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<r_D) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_D) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $93: 
  begin
    tmp2:=(r_A-r_E) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<r_E) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_E) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $94: 
  begin
    tmp2:=(r_A-r_H) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<r_H) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_H) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $95: 
  begin
    tmp2:=(r_A-r_L) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<r_L) then 
    begin
      r_F:=r_F or f_C;
    end;
    
    if (((tmp2  xor r_A  xor r_L) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $96: 
  begin
    tmp1:=do_read2(r_L,r_H);
    tmp2:=(r_A-tmp1) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<tmp1) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $97: 
  begin
    r_F:=flags[0];
    r_A:=0;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $98: 
  begin
    if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
    tmp2:=(r_A-r_B-tmp3) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<r_B+tmp3) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_B) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  

14

SOURCE_DELPHI\001\
uMain.pas part2

Код:
  $99: 
  begin
    if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
    tmp2:=(r_A-r_C-tmp3) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<(r_C+tmp3)) then
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_C) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $9A: 
  begin
    if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
    tmp2:=(r_A-r_D-tmp3) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<r_D+tmp3) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_D) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $9B: 
  begin
    if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
    tmp2:=(r_A-r_E-tmp3) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<r_E+tmp3) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_E) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $9C: 
  begin
    if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
    tmp2:=(r_A-r_H-tmp3) and $FF;
    r_F:=flags[tmp2];

    if (r_A<r_H+tmp3) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_H) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $9D: 
  begin
    if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
    tmp2:=(r_A-r_L-tmp3) and $FF;
    r_F:=flags[tmp2];

    if (r_A<r_L+tmp3) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_L) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $9E: 
  begin
    tmp1:=do_read2(r_L,r_H);
    if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
    tmp2:=(r_A-tmp1-tmp3) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<tmp1+tmp3) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $9F: 
  begin
    if ((r_F and f_C)<>0) then tmp2:=$FF else tmp2:=0;
    r_F:=flags[tmp2];
    
    if (tmp2<>0) then 
    begin
      r_F:=r_F or (f_A or f_C);
    end;
    r_A:=tmp2;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $A0: 
  begin
    r_A:=r_A and r_B;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;

  $A1: 
  begin
    r_A:=r_A and r_C;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $A2: 
  begin
    r_A:=r_A and r_D;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $A3: 
  begin
    r_A:=r_A and r_E;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $A4: 
  begin
    r_A:=r_A and r_H;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $A5: 
  begin
    r_A:=r_A and r_L;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $A6: 
  begin
    tmp1:=do_read2(r_L,r_H);
    r_A:=r_A and tmp1;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $A7: 
  begin
    r_A:=r_A and r_A;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $A8: 
  begin
    r_A:=r_A xor r_B;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $A9: 
  begin
    r_A:=r_A  xor r_C;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;

  end;

  $AA:
  begin
    r_A:=r_A xor r_D;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $AB: 
  begin
    r_A:=r_A  xor r_E;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;

  end;

  $AC:
  begin
    r_A:=r_A  xor r_H;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $AD: 
  begin
    r_A:=r_A  xor r_L;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $AE: 
  begin
    tmp1:=do_read2(r_L,r_H);
    r_A:=r_A xor tmp1;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+7;
    r_PC:=r_PC+1;

  end;

  $AF:
  begin
    r_A:=0;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $B0: 
  begin
    r_A:=r_A or r_B;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;

  end;

  $B1:
  begin
    r_A:=r_A or r_C;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $B2: 
  begin
    r_A:=r_A or r_D;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;

  end;

  $B3:
  begin
    r_A:=r_A or r_E;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;

  end;

  $B4:
  begin
    r_A:=r_A or r_H;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $B5: 
  begin
    r_A:=r_A or r_L;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;

  end;

  $B6:
  begin
    tmp1:=do_read2(r_L,r_H);
    r_A:=r_A or tmp1;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+7;
    r_PC:=r_PC+1;

  end;

  $B7:
  begin
    r_A:=r_A or r_A;
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+4;
    r_PC:=r_PC+1;

  end;

  $B8:
  begin
    tmp2:=(r_A-r_B) and $FF;
    r_F:=flags[tmp2];

    if (r_A<r_B) then
    begin
      r_F:=(r_F or f_C);
    end;

    if (((tmp2  xor r_A  xor r_B) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    clock:=clock+4;
    r_PC:=r_PC+1;

  end;

  $B9:
  begin
    tmp2:=(r_A-r_C) and $FF;
    r_F:=flags[tmp2];

    if (r_A<r_C) then
    begin
      r_F:=(r_F or f_C);
    end;

    if (((tmp2  xor r_A  xor r_C) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    clock:=clock+4;
    r_PC:=r_PC+1;

  end;

  $BA:
  begin
    tmp2:=(r_A-r_D) and $FF;
    r_F:=flags[tmp2];

    if (r_A<r_D) then
    begin
      r_F:=(r_F or f_C);
    end;

    if (((tmp2  xor r_A  xor r_D) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    clock:=clock+4;
    r_PC:=r_PC+1;

  end;

  $BB:
  begin
    tmp2:=(r_A-r_E) and $FF;
    r_F:=flags[tmp2];

    if (r_A<r_E) then
    begin
      r_F:=(r_F or f_C);
    end;

    if (((tmp2  xor r_A  xor r_E) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $BC: 
  begin
    tmp2:=(r_A-r_H) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<r_H) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_H) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $BD: 
  begin
    tmp2:=(r_A-r_L) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<r_L) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_L) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $BE: 
  begin
    tmp1:=do_read2(r_L,r_H);
    tmp2:=(r_A-tmp1) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<tmp1) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $BF: 
  begin
    r_F:=flags[0];
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $C0: 
  begin
    
    if ((r_F and f_Z)<>0) then
     begin
      clock:=clock+5;
      r_PC:=r_PC+1;
     end
        else
     begin
      r_PC:=do_read(r_SP);
      r_PC:=r_PC+(do_read(r_SP+1) shl 8);
      r_SP:=(r_SP+2) and $FFFF;
      clock:=clock+11;
     end;
  end;

  $C1:
  begin
    r_C:=do_read(r_SP);
    r_B:=do_read(r_SP+1);
    r_SP:=(r_SP+2) and $FFFF;
    clock:=clock+10;
    r_PC:=r_PC+1;

  end;

  $C2:
  begin

    if ((r_F and f_Z)<>0) then
    begin
      clock:=clock+10;
      r_PC:=r_PC+3;
    end
    else
    begin
      r_PC:=do_read(r_PC+1)+((do_read(r_PC+2) shl 8));
      clock:=clock+10;
    end;
  end;

  $C3:
  begin
    r_PC:=do_read(r_PC+1)+((do_read(r_PC+2) shl 8));
    clock:=clock+10;
  end;

  $C4:
  begin
    if ((r_F and f_Z)<>0) then
    begin
      clock:=clock+11;
      r_PC:=r_PC+3;
    end
        else
        begin
      tmp1:=do_read(r_PC+1)+((do_read(r_PC+2) shl 8));
      r_SP:=(r_SP-2) and $FFFF;
      r_PC:=r_PC+3;
      do_write(r_SP,r_PC and $FF);
      do_write(r_SP+1,(r_PC shr 8) and $FF);
      r_PC:=tmp1;
      clock:=clock+17;

    end;
  end;

  $C5:
  begin
    r_SP:=(r_SP-2) and $FFFF;
    do_write(r_SP,r_C);
    do_write(r_SP+1,r_B);
    clock:=clock+11;
    r_PC:=r_PC+1;

  end;

  $C6:
  begin
    tmp1:=do_read(r_PC+1);
    tmp2:=r_A+tmp1;
    r_F:=flags[tmp2 and $FF];

    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then
    begin
      r_F:=r_F or f_A;
    end;

    if (tmp2>$FF) then
    begin
      r_F:=r_F or f_C;
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+7;
    r_PC:=r_PC+2;

  end;

  $C7:
  begin
    r_SP:=(r_SP-2) and $FFFF;
    inc(r_PC);
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=0*8;
    clock:=clock+11;

  end;

  $C8:
  begin

    if ((r_F and f_Z)=0) then

    begin
      clock:=clock+5;
      r_PC:=r_PC+1;
    end
        else
    begin

      r_PC:=do_read(r_SP);
      r_PC:=r_PC+(do_read(r_SP+1) shl 8);
      r_SP:=(r_SP+2) and $FFFF;
      clock:=clock+11;

    end;
  end;
  
  $C9: 
  begin
    r_PC:=do_read(r_SP);
    r_PC:=r_PC+(do_read(r_SP+1) shl 8);
    r_SP:=(r_SP+2) and $FFFF;
    clock:=clock+11;
    
  end;
  
  $CA: 
  begin
    
    if ((r_F and f_Z)=0) then
    begin
      clock:=clock+10;
      r_PC:=r_PC+3;
    end
        else
    begin
      r_PC:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      clock:=clock+10;

    end;

  end;
  
  $CB: 
  begin
    if (signal_inv_opc()) then
           begin
           end
           else
           begin
            r_PC:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
            clock:=clock+10;
           end;
    
  end;
  
  $CC: 
  begin
    
    if ((r_F and f_Z)=0) then
    begin
      clock:=clock+11;
      r_PC:=r_PC+3;
    end
    else
    begin
      tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      r_SP:=(r_SP-2) and $FFFF;
      r_PC:=r_PC+3;
      do_write(r_SP,r_PC and $FF);
      do_write(r_SP+1,(r_PC shr 8) and $FF);
      r_PC:=tmp1;
      clock:=clock+17;
    end
  end;
  
  $CD: 
  begin
    tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
    r_SP:=(r_SP-2) and $FFFF;
    r_PC:=r_PC+3;
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=tmp1;
    clock:=clock+17;
    
  end;
  
  $CE: 
  begin
    tmp1:=do_read(r_PC+1);
    tmp2:=r_A+tmp1;
    if ((r_F and f_C)<>0) then tmp2:=tmp2+1 else  tmp2:=tmp2+0;
    r_F:=flags[tmp2 and $FF];
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=r_F or f_A;
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=r_F or f_C;
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+7;
    r_PC:=r_PC+2;
    
  end;
  
  $CF: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    inc(r_PC);
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=1*8;
    clock:=clock+11;
    
  end;
  
  $D0: 
  begin
    
    if ((r_F and f_C)<>0) then
    begin
      clock:=clock+5;
      r_PC:=r_PC+1;
    end
     else
     begin
      r_PC:=do_read(r_SP);
      r_PC:=r_PC+(do_read(r_SP+1) shl 8);
      r_SP:=(r_SP+2) and $FFFF;
      clock:=clock+11;
    end
  end;
  
  $D1: 
  begin
    r_E:=do_read(r_SP);
    r_D:=do_read(r_SP+1);
    r_SP:=(r_SP+2) and $FFFF;
    clock:=clock+10;
    r_PC:=r_PC+1;
    
  end;
  
  $D2: 
  begin
    if ((r_F and f_C)<>0) then

    begin
      clock:=clock+10;
      r_PC:=r_PC+3;
    end
     else
    begin
      r_PC:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      clock:=clock+10;
    end;
  end;
  
  $D3: 
  begin
    do_output(do_read(r_PC+1),r_A);
    clock:=clock+10;
    r_PC:=r_PC+2;
    
  end;
  
  $D4: 
  begin
    
    if ((r_F and f_C)<>0) then
   
    begin
      clock:=clock+11;
      r_PC:=r_PC+3;
    end
     else
    begin
      tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      r_SP:=(r_SP-2) and $FFFF;
      r_PC:=r_PC+3;
      do_write(r_SP,r_PC and $FF);
      do_write(r_SP+1,(r_PC shr 8) and $FF);
      r_PC:=tmp1;
      clock:=clock+17;
    end;
  end;
  
  $D5: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    do_write(r_SP,r_E);
    do_write(r_SP+1,r_D);
    clock:=clock+11;
    r_PC:=r_PC+1;
    
  end;
  
  $D6: 
  begin
    tmp1:=do_read(r_PC+1);
    tmp2:=(r_A-tmp1) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<tmp1) then 
    begin
      r_F:=r_F or f_C;
    end;
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=r_F or f_A;
    end;
    r_A:=tmp2;
    clock:=clock+7;
    r_PC:=r_PC+2;
    
  end;
  
  $D7: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    inc(r_PC);
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=2*8;
    clock:=clock+11;
    
  end;
  
  $D8: 
  begin
    
    if ((r_F and f_C)=0) then
    begin
      clock:=clock+5;
      r_PC:=r_PC+1;
    end
    else
    begin
      r_PC:=do_read(r_SP);
      r_PC:=r_PC+do_read(r_SP+1) shl 8;
      r_SP:=(r_SP+2) and $FFFF;
      clock:=clock+11;
    end;
  end;
  
  $D9: 
  begin
    if (signal_inv_opc()) then
           begin
           end
           else
           begin
            r_PC:=do_read(r_SP);
            r_PC:=r_PC+do_read(r_SP+1) shl 8;
            r_SP:=(r_SP+2) and $FFFF;
            clock:=clock+11;
           end;
    
  end;
  
  $DA: 
  begin
    
    if ((r_F and f_C)=0) then
    begin
      clock:=clock+10;
      r_PC:=r_PC+3;
    end
     else
    begin
      r_PC:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      clock:=clock+10;
    end;
  end;
  
  $DB: 
  begin
    r_A:=do_input(do_read(r_PC+1));
    clock:=clock+10;
    r_PC:=r_PC+2;
    
  end;
  
  $DC: 
  begin
    
    if ((r_F and f_C)=0) then
    begin
      clock:=clock+11;
      r_PC:=r_PC+3;
    end
    else
    begin
      tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      r_SP:=(r_SP-2) and $FFFF;
      r_PC:=r_PC+3;
      do_write(r_SP,r_PC and $FF);
      do_write(r_SP+1,(r_PC shr 8) and $FF);
      r_PC:=tmp1;
      clock:=clock+17;
    end;
  end;
  
  $DD:    begin
    if (signal_inv_opc()) then
    begin

    end
    else
    begin
    tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
    r_SP:=(r_SP-2) and $FFFF;
    r_PC:=r_PC+3;
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=tmp1;
    clock:=clock+17;
    end;
  end;


  $ED:    begin
    if (signal_inv_opc()) then
    begin

    end
    else
    begin
    tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
    r_SP:=(r_SP-2) and $FFFF;
    r_PC:=r_PC+3;
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=tmp1;
    clock:=clock+17;
    end;
  end;


  $FD:
  begin
    if (signal_inv_opc()) then  
    begin

    end
    else
    begin
    tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
    r_SP:=(r_SP-2) and $FFFF;
    r_PC:=r_PC+3;
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=tmp1;
    clock:=clock+17;
    end;
  end;

  $DE: 
  begin
    tmp1:=do_read(r_PC+1);
    if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
    tmp2:=(r_A-tmp1-tmp3) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<tmp1+tmp3) then 
    begin
      r_F:=r_F or f_C;
    end;
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=r_F or f_A;
    end;
    r_A:=tmp2;
    clock:=clock+7;
    r_PC:=r_PC+2;
    
  end;
  
  $DF: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    inc(r_PC);
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=3*8;
    clock:=clock+11;
    
  end;
  
  $E0: 
  begin
    if ((r_F and f_P)<>0) then
    begin
      clock:=clock+5;
      r_PC:=r_PC+1;
    end
    else
    begin
      r_PC:=do_read(r_SP);
      r_PC:=r_PC+do_read(r_SP+1) shl 8;
      r_SP:=(r_SP+2) and $FFFF;
      clock:=clock+11;
    end ;
    
  end;
  
  $E1: 
  begin
    r_L:=do_read(r_SP);
    r_H:=do_read(r_SP+1);
    r_SP:=(r_SP+2) and $FFFF;
    clock:=clock+10;
    r_PC:=r_PC+1;
    
  end;
  
  $E2: 
  begin
    
    if ((r_F and f_P)<>0) then
    
    begin
      clock:=clock+10;
      r_PC:=r_PC+3;
    end
    else
    begin
      r_PC:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      clock:=clock+10;

    end;
    
  end;
  
  $E3: 
  begin
    tmp1:=do_read(r_SP);
    do_write(r_SP,r_L);
    r_L:=tmp1;
    tmp1:=do_read(r_SP+1);
    do_write(r_SP+1,r_H);
    r_H:=tmp1;
    clock:=clock+18;
    r_PC:=r_PC+1;
    
  end;
  
  $E4: 
  begin
    
    if ((r_F and f_P)<>0) then
    
    begin
      clock:=clock+11;
      r_PC:=r_PC+3;
    end
    else
    begin
      tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      r_SP:=(r_SP-2) and $FFFF;
      r_PC:=r_PC+3;
      do_write(r_SP,r_PC and $FF);
      do_write(r_SP+1,(r_PC shr 8) and $FF);
      r_PC:=tmp1;
      clock:=clock+17;

    end;
    
  end;
  
  $E5: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    do_write(r_SP,r_L);
    do_write(r_SP+1,r_H);
    clock:=clock+11;
    r_PC:=r_PC+1;
    
  end;
  
  $E6: 
  begin
    r_A:=r_A and do_read(r_PC+1);
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+7;
    r_PC:=r_PC+2;
  end;
  
  $E7: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    inc(r_PC);
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=4*8;
    clock:=clock+11;
    
  end;
  
  $E8: 
  begin
    if ((r_F and f_P)=0) then
    begin
      clock:=clock+5;
      r_PC:=r_PC+1;
    end
     else
    begin
      r_PC:=do_read(r_SP);
      r_PC:=r_PC+do_read(r_SP+1) shl 8;
      r_SP:=(r_SP+2) and $FFFF;
      clock:=clock+11;

    end;
    
  end;
  
  $E9: 
  begin
    r_PC:=(r_H shl 8)+r_L;
    clock:=clock+5;
  end;
  
  $EA: 
  begin
    
    if ((r_F and f_P)=0) then
    begin
      clock:=clock+10;
      r_PC:=r_PC+3;  
    end
    else
    begin
      r_PC:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      clock:=clock+10;

    end;
  end;
  
  $EB: 
  begin
    tmp1:=r_D;
    r_D:=r_H;
    r_H:=tmp1;
    tmp1:=r_E;
    r_E:=r_L;
    r_L:=tmp1;
    clock:=clock+4;
    r_PC:=r_PC+1;
    
  end;
  
  $EC: 
  begin
    if ((r_F and f_P)=0) then
    begin
      clock:=clock+11;
      r_PC:=r_PC+3;
    end
    else
    begin
      tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      r_SP:=(r_SP-2) and $FFFF;
      r_PC:=r_PC+3;
      do_write(r_SP,r_PC and $FF);
      do_write(r_SP+1,(r_PC shr 8) and $FF);
      r_PC:=tmp1;
      clock:=clock+17;
    end;
  end;
  
  $EE: 
  begin
    r_A:= r_A xor do_read(r_PC+1);
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+7;
    r_PC:=r_PC+2;
  end;
  
  $EF: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    inc(r_PC);
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=5*8;
    clock:=clock+11;
  end;
  
  $F0: 
  begin
    if ((r_F and f_S)<>0) then
     begin
      clock:=clock+5;
      r_PC:=r_PC+1;
     end
     else
     begin
      r_PC:=do_read(r_SP);
      r_PC:=r_PC+(do_read(r_SP+1) shl 8);
      r_SP:=(r_SP+2) and $FFFF;
      clock:=clock+11;
    end;
  end;
  
  $F1: 
  begin
    r_F:=do_read(r_SP);
    r_A:=do_read(r_SP+1);
    r_SP:=(r_SP+2) and $FFFF;
    clock:=clock+10;
    r_PC:=r_PC+1;
  end;
  
  $F2: 
  begin
    if ((r_F and f_S)<>0) then
    begin
      clock:=clock+10;
      r_PC:=r_PC+3;
    end
    else
    begin
      r_PC:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      clock:=clock+10;
    end;
  end;
  
  $F4: 
  begin
    
    if ((r_F and f_S)<>0) then
    begin
      clock:=clock+11;
      r_PC:=r_PC+3;
    end
    else
    begin
      tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      r_SP:=(r_SP-2) and $FFFF;
      r_PC:=r_PC+3;
      do_write(r_SP,r_PC and $FF);
      do_write(r_SP+1,(r_PC shr 8) and $FF);
      r_PC:=tmp1;
      clock:=clock+17;
    end;
  end;
  
  $F5: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    do_write(r_SP,r_F);
    do_write(r_SP+1,r_A);
    clock:=clock+11;
    r_PC:=r_PC+1;
    
  end;
  
  $F6: 
  begin
    r_A:=r_A or do_read(r_PC+1);
    r_F:=flags[r_A] or (r_F and f_A);
    clock:=clock+7;
    r_PC:=r_PC+2;
    
  end;
  
  $F7: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    inc(r_PC);
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=6*8;
    clock:=clock+11;
    
  end;
  
  $F8: 
  begin
    if ((r_F and f_S)=0) then
    begin
      clock:=clock+5;
      r_PC:=r_PC+1;
    end
     else
    begin
      r_PC:=do_read(r_SP);
      r_PC:=r_PC+(do_read(r_SP+1) shl 8);
      r_SP:=(r_SP+2) and $FFFF;
      clock:=clock+11;

    end;
  end;
  
  $F9: 
  begin
    r_SP:=(r_H shl 8)+r_L;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $FA: 
  begin
    if ((r_F and f_S)=0) then
    begin
      clock:=clock+10;
      r_PC:=r_PC+3;
    end
     else
    begin
      r_PC:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      clock:=clock+10;
    end;
  end;
  
  $FC: 
  begin
    if ((r_F and f_S)=0) then
    begin
      clock:=clock+11;
      r_PC:=r_PC+3;
    end
    else
    begin
      tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      r_SP:=(r_SP-2) and $FFFF;
      r_PC:=r_PC+3;
      do_write(r_SP,r_PC and $FF);
      do_write(r_SP+1,(r_PC shr 8) and $FF);
      r_PC:=tmp1;
      clock:=clock+17;
    end;
  end;
  
  $FE: 
  begin
    tmp1:=do_read(r_PC+1);
    tmp2:=(r_A-tmp1) and $FF;
    r_F:=flags[tmp2];
    
    if (r_A<tmp1) then 
    begin
      r_F:=r_F or f_C;
    end;
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=r_F or f_A;
    end;
    clock:=clock+7;
    r_PC:=r_PC+2;
    
  end;
  
  $FF: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    inc(r_PC);
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=7*8;
    clock:=clock+11;
    
  end
  else
  begin
     // cpu_halt_state:=true;
     // cpu_halt_reason:=halt_inv;
  end;

end;
end;
end;


procedure TMainForm.draw_screen;   //Рисуем с video на экран  (Форму)

var
  i,vertX,gorY : word;
begin
  i:=0;
  vertX:=0;
  gorY:=0;
  while (i<$4000) do
  begin
   if video[i]<>VideoDirty[i] then //сравниваем значения , а есть ли изменения
        begin
          //WriteVRAM(video[i],vertX,gorY);   //старый способ каждый раз расчет шел
        if not N7.Checked then  // черно белое ТВ
          begin
          gamecanvas.Canvas.Pixels[vertX,gorY]:=  SuperColor[ports[$C1],video[i],1];
          gamecanvas.Canvas.Pixels[vertX+1,gorY]:=SuperColor[ports[$C1],video[i],2];
          gamecanvas.Canvas.Pixels[vertX+2,gorY]:=SuperColor[ports[$C1],video[i],3];
          gamecanvas.Canvas.Pixels[vertX+3,gorY]:=SuperColor[ports[$C1],video[i],4];
          end
          else
          begin
          gamecanvas.Canvas.Pixels[vertX,gorY]:=  GrayTV(SuperColor[ports[$C1],video[i],1]);
          gamecanvas.Canvas.Pixels[vertX+1,gorY]:=GrayTV(SuperColor[ports[$C1],video[i],2]);
          gamecanvas.Canvas.Pixels[vertX+2,gorY]:=GrayTV(SuperColor[ports[$C1],video[i],3]);
          gamecanvas.Canvas.Pixels[vertX+3,gorY]:=GrayTV(SuperColor[ports[$C1],video[i],4]);
          end;

        end;
    vertX:=vertX+4;
    if vertX>=256 then begin vertX:=0; gorY:=gorY+1; end;
    inc(i);
  end;
{$R-}
for I := 0 to $4000 do VideoDirty[i]:= video[i];  // быстрое копирование массивов
{$R+}
if FullScreen1.Checked then                        // на весь экран или нет
MainForm.Canvas.StretchDraw(rect(0,ToolBar1.Height,MainForm.Width-16,MainForm.Height-58), gamecanvas)
else
MainForm.Canvas.Draw(0,ToolBar1.Height,gamecanvas);
end;


procedure TMainForm.VRAMTest(c1,b:Byte);

Var

pix1,pix2,pix3,pix4:byte;
begin
   pix1:=0; pix2:=0; pix3:=0; pix4:=0;
  if (b and 128)=128 then pix1:=pix1+1;
  if (b and 8)=8     then pix1:=pix1+2;
  if (b and 64)=64   then pix2:=pix2+1;
  if (b and 4)=4     then pix2:=pix2+2;
  if (b and 32)=32   then pix3:=pix3+1;
  if (b and 2)=2     then pix3:=pix3+2;
  if (b and 16)=16   then pix4:=pix4+1;
  if (b and 1)=1     then pix4:=pix4+2;

  SuperColor[c1,b,1]:=compute_color_index(c1,Mycolor[pix1]);

  SuperColor[c1,b,2]:=compute_color_index(c1,Mycolor[pix2]);

  SuperColor[c1,b,3]:=compute_color_index(c1,Mycolor[pix3]);

  SuperColor[c1,b,4]:=compute_color_index(c1,Mycolor[pix4]);

end;

procedure TMainForm.CalculateColor;
var
  I,j: Integer;
begin
for I := 0 to 255 do
   for j := 0 to 255 do
    begin
       VRAMTest(i, j);
    end;
end;


function TMainForm.compute_color_index(port : byte; color : tcolor): tcolor;  // колор в зависимоти от порта С

begin
  Result:=ClBLACK;
  if ((port and $40)<>0) then Result:= (Result xor ClBLUE);
  if ((port and $20)<>0) then Result:= (Result xor clLime);
  if ((port and $10)<>0) then Result:= (Result xor ClRED);
  case color of
  clBLACK:
     begin
       if ((port and $08)=0) then
         begin
           Result:= (Result xor CLRED);
         end;
       if ((port and $04)=0) then
         begin
          Result:= (Result xor ClBLUE);
         end;
      end;
   clLime: begin
      Result:= (Result xor clLime);
      end;
   clred:  begin
       Result:= (Result xor ClRED);
       if ((port and $02)=0) then
           begin
             //Result:= (Result xor ClGREEN);
             Result:= (Result xor clLime);
           end;
        end;
    clBLUE: begin
         Result:= (Result xor ClBLUE);
         if ((port and $01)=0) then
            begin
             Result:= (Result xor ClRED);
            end;
       end;
end;
   // result:= ((Result and $07) shl 13) or ((Result and $38) shl 5) or ((Result and $C0) shr 3);
end;



procedure TMainForm.WriteVRAM(b:Byte;x,y: integer);  // рисуем на gamecanvas значения цвета , не забываем про порт С1

Var
pix1,pix2,pix3,pix4:byte;
begin
  pix1:=0; pix2:=0; pix3:=0; pix4:=0;        //вычисляем цвет в зависимисти от установки бит
  if (b and 128)=128 then pix1:=pix1+1;
  if (b and 8)=8     then pix1:=pix1+2;
  if (b and 64)=64   then pix2:=pix2+1;
  if (b and 4)=4     then pix2:=pix2+2;
  if (b and 32)=32   then pix3:=pix3+1;
  if (b and 2)=2     then pix3:=pix3+2;
  if (b and 16)=16   then pix4:=pix4+1;
  if (b and 1)=1     then pix4:=pix4+2;
  if N7.Checked then  // черно белое ТВ
    begin
      gamecanvas.Canvas.Pixels[x,y] := GrayTV(compute_color_index(ports[$C1],Mycolor[pix1]));
      gamecanvas.Canvas.Pixels[x+1,y]:=GrayTV(compute_color_index(ports[$C1],Mycolor[pix2]));
      gamecanvas.Canvas.Pixels[x+2,y]:=GrayTV(compute_color_index(ports[$C1],Mycolor[pix3]));
      gamecanvas.Canvas.Pixels[x+3,y]:=GrayTV(compute_color_index(ports[$C1],Mycolor[pix4]));
    end
    else
    begin
     gamecanvas.Canvas.Pixels[x,y]:=  compute_color_index(ports[$C1],Mycolor[pix1]);
     gamecanvas.Canvas.Pixels[x+1,y]:=compute_color_index(ports[$C1],Mycolor[pix2]);
     gamecanvas.Canvas.Pixels[x+2,y]:=compute_color_index(ports[$C1],Mycolor[pix3]);
     gamecanvas.Canvas.Pixels[x+3,y]:=compute_color_index(ports[$C1],Mycolor[pix4]);
     end;
end;



procedure TMainForm.FirstPusk; //первый запуск
 begin
 // создадим канву для рисования
 gamecanvas:=tbitmap.Create;
 gamecanvas.Width:=256;
 gamecanvas.Height:=256;

  ResetComp; // первоночальный сброс всего
  TimerMain.Enabled:=true; // запускаем основной таймер
end;

function TMainForm.readmask (keynum: word): word;    // маска клавы
begin
result:= $72FF;
case keynum of
      8: begin result:= $23FF end;  // BCK
     13: begin result:= $13FF end;  // ENTER
	   16: begin result:= $70FF end;  // SHIFT
     32: begin result:= $30FF end;  // SPC

     37: begin result:= $FF32 end;  //  <-
     38: begin result:= $FF31 end;  //  UP
     39: begin result:= $FF30 end;  //  ->
     40: begin result:= $FF33 end;  //  DOWN

     48: begin result:= $06FF end;  //   0
	   49: begin result:= $47FF end;  //   1
	   50: begin result:= $46FF end;  //   2
   	 51: begin result:= $45FF end;  //   3
  	 52: begin result:= $44FF end;  //   4
   	 53: begin result:= $43FF end;  //   5
   	 54: begin result:= $00FF end;  //   6
  	 55: begin result:= $01FF end;  //   7
  	 56: begin result:= $02FF end;  //   8
  	 57: begin result:= $07FF end;  //   9

  	 65: begin result:= $64FF end;  //   A
     66: begin result:= $31FF end;  //   B
     67: begin result:= $57FF end;  //   C
     68: begin result:= $27FF end;  //   D
     69: begin result:= $54FF end;  //   E
     70: begin result:= $67FF end;  //   F
     71: begin result:= $10FF end;  //   G
  	 72: begin result:= $16FF end;  //   H
  	 73: begin result:= $75FF end;  //   I
  	 74: begin result:= $52FF end;  //   J
     75: begin result:= $55FF end;  //   K
   	 76: begin result:= $22FF end;  //   L
  	 77: begin result:= $76FF end;  //   M
  	 78: begin result:= $53FF end;  //   N
   	 79: begin result:= $21FF end;  //   O
   	 80: begin result:= $63FF end;  //   P
  	 81: begin result:= $71FF end;  //   Q
     82: begin result:= $20FF end;  //   R
   	 83: begin result:= $77FF end;  //   S
   	 84: begin result:= $74FF end;  //   T
     85: begin result:= $56FF end;  //   U
  	 86: begin result:= $26FF end;  //   V
  	 87: begin result:= $65FF end;  //   W
   	 88: begin result:= $73FF end;  //   X
   	 89: begin result:= $66FF end;  //   Y
  	 90: begin result:= $17FF end;  //   Z

  	 107: begin result:= $05FF end;  //   =/+ -> =/-
  	 109: begin result:= $05FF end;  //   -/_ -> =/-

  	 114: begin result:= $FF23 end;  // F3
  	 115: begin result:= $FF22 end;  // F4
   	 116: begin result:= $FF21 end;  // F5

  	 36: begin result:= $FF20 end;  // Home

  	 219: begin result:= $11FF end;  //   [
  	 221: begin result:= $12FF end;  //   ]
  	 190: begin result:= $24FF end;  //   .
   	 188: begin result:= $37FF end;  //   ,
   	 192: begin result:= $72FF end;  //
end;

end;

procedure TMainForm.FormActivate(Sender: TObject);
begin
if FPusk then    // а это первый ли запуск
    begin
    FPusk:=false;
    FirstPusk;
    end;
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
DragAcceptFiles(MainForm.Handle, true);   // сделаем драг анд дроб :)
CalculateColor;
FPusk:=true; // запомним первый запуск
English1Click(Sender);
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin
DragAcceptFiles(Handle, False);
ServiceThread.Free;
end;

procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;  //опрос клавы
  Shift: TShiftState);
begin
    kbd(readmask(key),true);  // нажали
    i8080_do_opcodes(opcodes_to_run);
end;

procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
   kbd(readmask(key),false); // отпустии
end;

procedure TMainForm.FullScreen1Click(Sender: TObject);
begin
FullScreen1.Checked:= not FullScreen1.Checked;
if not FullScreen1.Checked then
MainForm.Canvas.FillRect(rect(0,0,MainForm.Width,MainForm.Height));

end;

procedure TMainForm.TimerMainTimer(Sender: TObject);  // основной таймер
var
j,a: word;
i: integer;
s: string;
begin
if (pause) then  // если пауза курим бамбук :)
  begin
    exit;
  end;
 i8080_do_opcodes(opcodes_to_run);
 draw_screen;
 if clock<100000 then
  begin
    playTone;
  end;
 speaked:= 0;
end;

procedure TMainForm.ResetComp;
begin
 r_B := 0;  // обнулим регистры
 r_C := 0;
 r_D := 0;
 r_E := 0;
 r_H := 0;
 r_L := 0;
 r_A := 0;
 r_F := 0;
 r_PC := 0;
 r_SP := 0;

 clock := 0; // обнулим часики

 halt_inv := 1;
 halt_opc := 2;
 halt_hlt := 3;

 halt_bpx := 4;
 halt_bpr := 5;
 halt_bpw := 6;
 halt_bpi := 7;
 halt_bpo := 8;



 pause := false;
 FPS := 50;


 speaked := 0;

 f_S := (1 SHL 7);
 f_Z :=( 1 SHL 6);
 f_5 := (1 SHL 5);
 f_A := (1 SHL 4);
 f_3 := (1 SHL 3);
 f_P := (1 SHL 2);
 f_1 := (1 SHL 1);
 f_C := (1 SHL 0);

 BasicStack := $AFC1;
 BasicHotEntry := $02FD;
 BasicProgBegin := $0243;
 BasicProgEnd := $0245;


  fillchar(VideoDirty,sizeof(VideoDirty),257);

  soundEnabled := false;
 // opcodes_to_run := round ((1411200*4)/FPS);
  opcodes_to_run := round ((1411200*2)/FPS);
  curSnd := 0;
  restClock := 0;
  init_memory();
  reset1();
  load_bios();
  i8080_do_opcodes(0);
end;

procedure TMainForm.ResetCPU1Click(Sender: TObject);
begin
ResetComp;
end;


function TMainForm.GrayTV(RGBColor : TColor) : TColor;  // эффект черно белого телевизора
var
Gray : byte;
begin
Gray := Round((0.30 * GetRValue(RGBColor)) +
               (0.59 * GetGValue(RGBColor)) +
               (0.11 * GetBValue(RGBColor )));
Result := RGB(Gray, Gray, Gray);                 // грубо очень грубо :-)
end;


procedure TMainForm.English1Click(Sender: TObject);
begin
English1.Checked:=true;
Russian1.Checked:=false;
MainForm.Caption:='PK-01 Lvov emulator';

//DebuggerForm.TabSheet1.Caption:='Assembler';
//DebuggerForm.TabSheet2.Caption:='Find-replace in memory';


N1.Caption:='File';
N2.Caption:='Open';
ResetCPU1.Caption:='Reset CPU';
N11.Caption:='Pause';
N4.Caption:='Exit';

N5.Caption:='Setup';
N7.Caption:='Balck-and-white TV';
N10.Caption:='Keyboard';
N13.Caption:='Sound';
N15.Caption:='Language';

N17.Caption:='About';
end;

procedure TMainForm.Russian1Click(Sender: TObject);
begin
Russian1.Checked:=true;
English1.Checked:=false;
MainForm.Caption:='ПК-01 Львов эмулятор';

//DebuggerForm.TabSheet1.Caption:='Ассемблер';
//DebuggerForm.TabSheet2.Caption:='Поиск-замена в памяти';

N1.Caption:='Файл';
N2.Caption:='Открыть';
ResetCPU1.Caption:='Reset CPU';
N11.Caption:='Пауза';
N4.Caption:='Выход';

N5.Caption:='Настройки';
N7.Caption:='ЧБ телевизор';
N10.Caption:='Клавиатура';
N13.Caption:='Звук';
N15.Caption:='Язык программы';

N17.Caption:='О программе';
end;


// ###################################################ГРЕБАННЫЙ ЗВУК :-) ##############################################################


procedure TMainForm.putSound(bt : byte);
begin
  if (((bt xor ports[$C2]) and 1)<>0) then
  begin
    speaker[speaked]:=clock;
    speaked:=speaked+1;
  end;
end;

procedure TMainForm.playTone();
var
tickPos,speakerPos,i: integer;
Buffer: array of byte;
begin
for I := 0 to 2000 do soundData[i]:=0;
  tickPos:=0-restClock;
  speakerPos:=0;
  i:=0;
  while (i<2000) do // 2000 длина массива soundData
    begin
     if (speakerPos<speaked) and (tickPos>=speaker[speakerPos]) then
      begin
       curSnd:=255-curSnd;
       inc(speakerPos);
      end;
    tickPos:=tickPos+32;
    soundData[i]:=curSnd;
    inc(i);
  end;
  restClock:=(clock+restClock) mod 32;
 if N13.Checked then
       begin
         //ServiceThread:= TserviceThread.Create(false);
        // PlayBuffer(soundData);    // вот тут будем петь :-)
       end;
end;

procedure TMainForm.enableSound;
begin
	soundEnabled:= true;
end;

procedure TMainForm.PlayBuffer(Buffer: array of byte);  //процедура проигрывает буфер
{var Err: integer;
hEvent: Thandle; }
begin
{ with header do
   begin
     wFormatTag := WAVE_FORMAT_PCM;  // формат РСМ
     nChannels := 1;    // моно
     nSamplesPerSec := 44100;  // частота дискретитатции 44.1 Кгц
     wBitsPerSample := 8; // выборка 8 бит
     nBlockAlign := nChannels * (wBitsPerSample div 8);
     nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;
     cbSize := 0;
   end;
// if Opened = true then stopPlay;
   hEvent:=CreateEvent(nil,false,false,nil);
   if WaveOutOpen(addr(waveOut), 0, @header, hEvent, 0, CALLBACK_WINDOW) <> MMSYSERR_NOERROR then
      begin
        CloseHandle(hEvent);
        Exit;
      end;
   pBuf := GlobalAlloc(GMEM_MOVEABLE and GMEM_SHARE, length(Buffer));
   pBuffer := GlobalLock(pBuf);
   with outHdr do
     begin
      lpData := PBuffer;
      dwBufferLength := length(Buffer);
      dwUser := 0;
      dwFlags := 0;
      dwLoops := 0
     end;
   err:= WaveOutPrepareHeader(waveOut, @outHdr, sizeof(outHdr));
   if Err <> 0 then Exit;
   copyMemory(pBuffer, @Buffer, length(Buffer));

   err:= WaveOutWrite(waveOut, @outHdr, sizeof(outHdr));
   if Err <> 0 then Exit;

   waveOutReset(waveOut);
   waveOutUnprepareHeader(waveOut,@outHdr,sizeof(wavehdr));
   waveOutClose(waveOut);  }
end;

procedure Tservicethread.Execute;
var
    Err: integer;
    header : TWaveFormatEx;
    waveOut : hWaveOut;
    outHdr : TWaveHdr;
    pBuf : tHandle;
    pBuffer : pointer;
    hEvent: Thandle;
begin
 with header do
   begin
     wFormatTag := WAVE_FORMAT_PCM;  // формат РСМ
     nChannels := 1;    // моно
     nSamplesPerSec := 44100;  // частота дискретитатции 44.1 Кгц
     wBitsPerSample := 8; // выборка 8 бит
     nBlockAlign := nChannels * (wBitsPerSample div 8);
     nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;
     cbSize := 0;
   end;
// if Opened = true then stopPlay;
   hEvent:=CreateEvent(nil,false,false,nil);
   if WaveOutOpen(addr(waveOut), 0, @header, hEvent, 0, CALLBACK_WINDOW) <> MMSYSERR_NOERROR then
      begin
        CloseHandle(hEvent);
        Exit;
      end;
   pBuf := GlobalAlloc(GMEM_MOVEABLE and GMEM_SHARE, length(soundData));
   pBuffer := GlobalLock(pBuf);
   with outHdr do
     begin
      lpData := PBuffer;
      dwBufferLength := length(soundData);
      dwUser := 0;
      dwFlags := 0;
      dwLoops := 0
     end;
   WaveOutPrepareHeader(waveOut, @outHdr, sizeof(outHdr));
   //copyMemory(pBuffer, @soundData, length(soundData));

// while not terminated do
  // begin
    WaveOutWrite(waveOut, @outHdr, sizeof(outHdr));
    WaitForSingleObject(hEvent,INFINITE);
 //  end;

   waveOutReset(waveOut);
   waveOutUnprepareHeader(waveOut,@outHdr,sizeof(wavehdr));
   waveOutClose(waveOut);
end;

end.

15

SOURCE_DELPHI\002\
EmulForKOS.dpr

Код:
program EmulForKOS;

uses
  Forms,
  Windows,
  uMain in 'uMain.pas' {MainForm};

{$R *.res}

begin
  SetThreadLocale(1049);
  Application.Initialize;
  Application.Title := 'ой кэбнб';
  Application.CreateForm(TMainForm, MainForm);
  Application.Run;
end.

16

SOURCE_DELPHI\002\
uMain.pas part1

Код:
unit uMain;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Menus,MMSystem,ShellAPI, ImgList, ComCtrls,
  ToolWin;
type

  TMainForm = class(TForm)
    TimerMain: TTimer;    MainMenu1: TMainMenu;
    N1: TMenuItem;    N2: TMenuItem;
    N3: TMenuItem;    N4: TMenuItem;
    OpenDialogLvt: TOpenDialog;
    ResetCPU1: TMenuItem;
    N11: TMenuItem;

    procedure TimerMainTimer(Sender: TObject);
    procedure do_write(addr : word; bt : byte);
    procedure i8080_init;
    procedure i8080_reset(addr: word);
    function  do_read(addr : integer): word;
    procedure do_write2(a_lo : word; a_hi : word; bt : byte);
    function  do_read2(a_lo : word; a_hi : word): word;
    function  compute_color_index(port : byte; color : tcolor): tcolor;
    procedure WriteVRAM(b:Byte;x,y: integer);
    procedure init_memory();
    function  do_input(port : byte): byte;
    procedure do_output(port : byte; bt : byte);
    procedure kbd(mask : word; press : boolean);
    procedure reset1;
    procedure load_bios;
    function  get_var(var1: word): word;
    procedure set_var(var1, val: word);
    procedure warm_start();
    procedure do_pause();
    procedure i8080_do_opcodes(nb_cycles : integer);
    procedure draw_screen();
    procedure FirstPusk;
    function  readmask (keynum: word): word;
    procedure N4Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure NewLoadFile(filenameDnD: string;start : boolean);
    procedure ResetComp;
    procedure ResetCPU1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure VRAMTest(c1,b:Byte);
    procedure CalculateColor;
    procedure Russian1Click(Sender: TObject);
    procedure English1Click(Sender: TObject);
    procedure Wmemory;
    procedure Rmemory;
    procedure Wflags;
    procedure Rflags;
  private
    { Private declarations }
  public
    procedure WMDropFiles(var Msg: TMessage); message wm_DropFiles;
    { Public declarations }
  end;

var
  MainForm: TMainForm;
  var { регистрики}   rgA,rgB,rgC,rgD,rgE,rgH,rgL,rgF,rgPC,rgSP :Cardinal;
  var { флаги}   fS, fZ, f5, fA, f3,fP,f1,fC : Cardinal;
  memoryM: array [0..65535] of byte;  // массив основной памяти $FFFF
  flagsM: array [0..256] of  word;


    opcode : byte; // код текущей операции !!!

    halt_inv :byte;
    halt_opc :byte;
    halt_hlt :byte;
    halt_bpx :byte;
    halt_bpr :byte;
    halt_bpw :byte;
    halt_bpi :byte;
    halt_bpo :byte;

    FPusk: boolean; // первый запуск

    gamecanvas: tbitmap; // сюда все рисуем перед выводом на форму


    video : array [0..16384] of byte;  // видео память
    VideoDirty : array [0..16384] of word; //буфер для быстрой прорисовки
    ports : array [0..256]   of byte;      // порты
    bios  : array [0..65535] of byte;    // массив для загрузки биоса, можно сразу грузить но вдруг пригодися
    Myfile: array [0..90000] of byte; //файл может быть большим DUMP SAV который

    SuperColor: array[0..255, 0..255,1..4] of Tcolor; // еще один вариант по цвету

    pause : boolean; //пауза в эмуляторе
    FPS : integer;  // frames per second :-)

    speaker: array [0..2000] of word; //массивы для звуков
    speaked : word;
    soundData: array [0..2000] of BYTE;
    soundEnabled : boolean;
   { header : TWaveFormatEx;
    waveOut : hWaveOut;
    outHdr : TWaveHdr;
    pBuf : tHandle;
    pBuffer : pointer;}


    myfilelength: word; // длина скачаного файла
    //_filePos : integer;

    r_Halted: boolean;

    kbd_base : array  [0..8] of byte;  // массивы опроса клавиатуры
    kbd_ext : array  [0..4] of byte;

    BasicStack : word;    // переменные для бейсик программ
    BasicHotEntry : word;
    BasicProgBegin : word;
    BasicProgEnd : word;

    opcodes_to_run : integer;

    curSnd : word;
    restClock : word;

const MyColor:array[0..3] of Tcolor=(clBlack,clLime,clBlue,clRed);

implementation
var Wmemory_a,Wmemory_b:Cardinal; procedure TMainForm.Wmemory; begin memoryM[Wmemory_a]:=Wmemory_b; end;
var Rmemory_a,Rmemory_result:Cardinal; procedure TMainForm.Rmemory; begin Rmemory_result:=memoryM[Rmemory_a];end;
var Wflags_a,Wflags_b:Cardinal; procedure TMainForm.Wflags; begin flagsM[Wflags_a]:=Wflags_b; end;
var Rflags_a,Rflags_result:Cardinal; procedure TMainForm.Rflags; begin Rflags_result:=flagsM[Rflags_a];end;

{$R *.dfm}

procedure TMainForm.WMDropFiles(var Msg: TMessage);   // порцедура отвечает за принятие перетаскиваемого файла
var
FileName: array[0..256] of char;
begin
DragQueryFile(THandle(Msg.WParam), 0, FileName, SizeOf(Filename));
MainForm.Caption:=FileName;
NewLoadFile(FileName,true);
DragFinish(THandle(Msg.WParam));
end;

procedure TMainForm.do_write(addr : word; bt : byte); // если нужно будем записывать :-)
begin
  addr:=(addr and $FFFF);
  if (addr>=$C000) then
  begin
    exit;
  end;
  if ((ports[$C2] and 2)<>0) then
  begin
    Wmemory_A:=addr; Wmemory_B:=bt; Wmemory;
  end
  else
     if (addr<$4000) then
       begin
         exit;
       end
       else
         if (addr<$8000) then
           begin
              video[addr-$4000]:=bt;
             // memory[addr]:=bt; // запишем еще и в память но не всегда
           end
           else
           begin
               Wmemory_A:=addr; Wmemory_B:=bt; Wmemory;
           end;
end;



procedure TMainForm.i8080_init;
var
  j,i : word;
begin
  i:=0;
  while (i<256) do
  begin
    //flags[i]:=f1 or fP;
    Wflags_a:=i;Wflags_b:=(f1 or fP);Wflags;
    j:=0;
    while (j<8) do
    begin
       if ((i and (1 SHL j))<>0) then
             begin
//                flags[i]:=(flags[i] xor fP);
    Rflags_a:=i;Rflags;
    Wflags_a:=i;Wflags_b:=(Rflags_Result xor fP);Wflags;
             end;
      inc(j);
    end;
       if ((i and $80)<>0) then
             begin
//               flags[i]:=(flags[i] or fS);
                   Rflags_a:=i;Rflags;
          Wflags_a:=i;Wflags_b:=(Rflags_Result or fS);Wflags;
             end;
       if (i=0) then
             begin
//               flags[i]:=(flags[i] or fZ);
                   Rflags_a:=i;Rflags;
          Wflags_a:=i;Wflags_b:=(Rflags_Result or fZ);Wflags;
             end;
    inc(i);
  end;
end;

procedure TMainForm.i8080_reset(addr: word);
begin
//  r_A:=0;  r_F:=0;  r_B:=0;  r_C:=0;  r_D:=0;  r_E:=0;  r_H:=0;  r_L:=0;
//  r_SP:=0;  r_Halted:=false;  clock:=0;  r_PC:=addr;
end;



function TMainForm.do_read(addr : integer): word; // считаем значение из пямяти
begin
  addr:=(addr and $FFFF);
   if ((ports[$C2] and 2)<>0) then
  begin

     Rmemory_A:=addr; Rmemory; result := Rmemory_result;
  end
  else
  if (addr>$7FFF) then
  begin
     Rmemory_A:=addr; Rmemory; result := Rmemory_result;
  end
  else if (addr<$4000) then
  begin
    result := 0;
  end
  else begin
    result := video[addr-$4000];
  end;
end;

procedure TMainForm.do_write2(a_lo : word; a_hi : word; bt : byte);  // адреса
begin
  do_write(a_lo+(a_hi SHL 8),bt);
end;

function TMainForm.do_read2(a_lo : word; a_hi : word): word;
begin
  result := do_read(a_lo+(a_hi SHL 8));
end;

procedure TMainForm.init_memory();    // подготовим все к запуску
var
  j , i : integer;
begin
  i:=$0000;
  while (i<$10000) do
  begin
         Wmemory_A:=i; Wmemory_B:=0; Wmemory;
    inc(i);
  end;
  i:=$0000;
  while (i<$4000) do begin
    video[i]:=0;
    inc(i);
  end;
  i:=$0000;
  while (i<$100) do begin
    ports[i]:=0;
    inc(i);
  end;
  i:=0;
  while (i<8) do begin
    kbd_base[i]:=0;
    inc(i);
  end;
  i:=0;
  while (i<4) do begin
    kbd_ext[i]:=0;
    inc(i);
  end;
  i:=0;
  while (i<256) do begin
//    flags[i]:=(f1 or fP);
          Wflags_a:=i;Wflags_b:=(f1 or fP);Wflags;
    j:=0;
    while (j<8) do begin
      if ((i and (1 shl j))<>0) then
      begin
//        flags[i]:= (flags[i] xor fP);
        Rflags_a:=i;Rflags;
        Wflags_a:=i;Wflags_b:=(Rflags_result xor fP);Wflags;
      end;
      inc(j);
    end;
    if ((i and $80)<>0) then
    begin
//      flags[i]:= (flags[i] or fS);
        Rflags_a:=i;Rflags;
        Wflags_a:=i;Wflags_b:=(Rflags_result or fS);Wflags;
    end;

    if (i=0) then
    begin
//      flags[i]:=(flags[i] or fZ);
        Rflags_a:=i;Rflags;
        Wflags_a:=i;Wflags_b:=(Rflags_result xor fZ);Wflags;
    end;
    inc(i);
  end;
end;


function TMainForm.do_input(port : byte): byte;  // работа со значениями портов in
var
  i,r : integer;
  nD2 ,nD0 : byte;
begin
  nD2:=0;
  nD0:=0;
  port:=$C0+(port and $13);
  case port of
  $C2:     begin result := ports[$C2]; end;
  $D1:     begin
             nD0:=not ports[$D0];
             r:=0;
             i:=0;
             while (i<8) do
             begin
              if ((nD0 and (1 SHL i))<>0) then
                 begin
                    r:=(r or kbd_base[i]);
                 end;
              inc(i);
             end;
             result :=  ((not r) and $FF);
           end;
   $D2:    begin
             nD2:= not ports[$D2];
             r:=0;
             i:=0;
             while (i<4) do
              begin
               if ((nD2 and (1 SHL i))<>0) then
                  begin
                   r:=(r or kbd_ext[i]);
                  end;
               inc(i);
              end;
              result := not ((r SHL 4) or (nD2 and $0F)) and $FF;
            end
     else
        begin
           result := $FF;
        end;
end;
end;

procedure TMainForm.do_output(port : byte; bt : byte); // out
begin
  port:=$C0+(port and $13);
  case port of
  $c1:  begin // изменение порта цвета
          fillchar(VideoDirty,sizeof(VideoDirty),257); // чистим массив
        end;

  end;
  ports[port]:=bt;
end ;



procedure TMainForm.kbd(mask : word; press : boolean); //  по маске вкл выкл клавишу
var
  brow : byte;
  erow : byte;
  bcol : byte;
  ecol : byte;
begin
  bcol:=(mask SHR 12) and $0F;
  brow:=(mask SHR 8) and $0F;
  ecol:=(mask SHR 4) and $0F;
  erow:=(mask SHR 0) and $0F;
  
  if ((brow<8) and (bcol<8)) then
  begin
   if (press) then
    begin
      kbd_base[bcol]:=(kbd_base[bcol] or (1 SHL brow));
    end else begin
      kbd_base[bcol]:= (kbd_base[bcol] and (not(1 SHL brow)));
    end;
  end;

  if ((erow<8) and (ecol<4)) then
  begin
    if (press) then
    begin
      kbd_ext[ecol]:= (kbd_ext[ecol]or (1 SHL erow));
    end else begin
      kbd_ext[ecol]:= (kbd_ext[ecol] and (not(1 SHL erow)));
    end;
  end;
end;

procedure TMainForm.reset1;    // полный ресет :)
var
  i : word;
begin
  i:=0;
  while (i<256) do begin
    ports[i]:=$FF;
    inc(i);
  end;
  i8080_init;
end;

procedure TMainForm.load_bios;    // загрузка биоса из файла
var
i: word;
b: byte;
f: file of byte;
begin
  i:=0;
  AssignFile(F,ExtractFilePath(Application.ExeName)+'\bios.dat');
  Reset(F);                   // проверять заголовок не будем :)
  while not eof(f) do
   begin
    read(F,b);
    bios[i]:=b; // загрузим в массив , а вдруг пригодится
    inc(i);
   end;
  closeFile(F);
  i:=0;
  while (i<$4000) do begin
    //memory[$C000+i]:=bios[22+i];
         Wmemory_A:=$C000+i; Wmemory_B:=bios[22+i]; Wmemory;
    inc(i);
  end;
end;


procedure TMainForm.N2Click(Sender: TObject);
begin
  OpenDialogLvt.InitialDir:=ExtractFilePath(Application.ExeName);
  if OpenDialogLvt.Execute then NewLoadFile(OpenDialogLvt.FileName,true);
end;

procedure TMainForm.N4Click(Sender: TObject);
begin
gamecanvas.Free;
close;
end;

function TMainForm.get_var(var1: word): word;  // чтение и запись нужных значений из пямяти
begin
//    result:= memory[var1] + memory[var1+1]*256;
end;

procedure TMainForm.set_var(var1, val: word);
begin
//    memory[var1]:= (val and $FF);
//    memory[var1+1]:= (round(val/256) and $FF);
end;

procedure TMainForm.warm_start();  // горячий запуск
begin
  ports[$C2]:=$FF;
  rgSP:=BasicStack;
  set_var(BasicStack,BasicHotEntry);
  rgPC:=BasicHotEntry;
end;

procedure TMainForm.NewLoadFile(filenameDnD: string; start : boolean);  //процедура загрузки всех видов файлов
var
f:file of byte;
b:Byte;
s: string;
posBas, Xend ,Xbeg ,Xrun : word;
i: integer;
begin
  s:='';
      AssignFile(f,filenameDnD); // распознаем что за файл
      Reset(f);
      for I:= 0 to 8  do
        begin
           read(f,b);
           s:=s+chr(b);
           //Myfile[j]:=strtoint(s);
           // Size(f);
           //seek(f,100);
        end;
      if s='LVOV/2.0/' then // стандартный LVT файл
      begin
         read(f,b);
         if b=$D0 then      // это бинарник
         begin
           seek(F,0); // вернемся к началу файла
           i:=0;
           while not eof(f) do
              begin
                read(F,b);
                Myfile[i]:=b;
                inc(i);
              end;
           myfilelength:=i;
           closeFile(F);     //закрываем файл
           Xbeg:=Myfile[16]+Myfile[17]*256;
           Xend:=Myfile[18]+Myfile[19]*256;
           Xrun:=Myfile[20]+Myfile[21]*256;
           if (start) then
              begin
                warm_start();
                rgPC:=Xrun;
              end;
           i:=0;
           while (i<=Xend-Xbeg) do
              begin
               do_write(Xbeg+i,Myfile[i+22]);
               inc(i);
              end;
         end
         else
         begin      //это бeйсик (надеюсь больше ничего нет :-) )
           seek(F,0); // вернемся к началу файла
           i:=0;
           while not eof(f) do
              begin
                read(F,b);
                Myfile[i]:=b;
                inc(i);
              end;
            myfilelength:=i-1;
            warm_start();
            posBas:=get_var(BasicProgBegin);
            i:=0;
            while (i<myfilelength-16) do
               begin
                do_write(posBas+i,Myfile[i+16]);
                inc(i);
               end;
              set_var(BasicProgEnd,posBas+myfilelength-16);
              // направим RUN
              MainForm.SetFocus;

              //i8080_do_opcodes(opcodes_to_run);


              //KeyboardForm.SendKeys('RUN');
         end;
       end;
      if s='LVOV/DUMP' then // стандартный SAV файл дампа эмулятор Калашникова
         begin
           seek(F,0); // вернемся к началу файла
           i:=0;
           while not eof(f) do
              begin
                read(F,b);
                Myfile[i]:=b;
                inc(i);
              end;
           i:=0;
           closeFile(F);
           while (i<$10000) do
           begin
            // memory[i]:=Myfile[17+i];
                Wmemory_A:=i; Wmemory_B:=Myfile[17+i]; Wmemory;
             inc(i);
           end;
           i:=0;
           while (i<$4000) do
           begin
            video[i]:=Myfile[17+$10000+i];
            inc(i);
           end;
           i:=0;
           while (i<$100) do
           begin
            ports[i]:=Myfile[17+$10000+$4000+i];
            inc(i);
           end;
           rgB:=Myfile[17+$10000+$4000+$100];
           rgH:=Myfile[17+$10000+$4000+$100+4];
           rgC:=Myfile[17+$10000+$4000+$100+1];
           rgL:=Myfile[17+$10000+$4000+$100+5];
           rgD:=Myfile[17+$10000+$4000+$100+2];
           rgA:=Myfile[17+$10000+$4000+$100+6];
           rgE:=Myfile[17+$10000+$4000+$100+3];
           rgF:=Myfile[17+$10000+$4000+$100+7];
           rgSP:=Myfile[17+$10000+$4000+$100+9]*256+Myfile[17+$10000+$4000+$100+8];
           rgPC:=Myfile[17+$10000+$4000+$100+11]*256+Myfile[17+$10000+$4000+$100+10];
           fillchar(VideoDirty,sizeof(VideoDirty),257); // чистим массив
           draw_screen;
         end;
end;

procedure  TMainForm.do_pause();
begin
	pause := not pause;
end;

procedure TMainForm.i8080_do_opcodes(nb_cycles : integer);    //выполнение комманд процессора
var tmp3,  tmp2,  tmp1,  opcode : integer;
var { регистрики}   r_A,r_B,r_C,r_D,r_E,r_H,r_L,r_F,r_PC,r_SP : integer;
clock:Cardinal;
{ флаги}   f_S, f_Z, f_5, f_A, f_3,f_P,f_1,f_C : Integer;
procedure rF1;
Begin
//r_F:=(flags[tmp2] or (r_F and f_C));
        Rflags_a:=tmp2;Rflags;
    r_F:=(Rflags_result or (r_F and f_C));
end;

procedure rF2;
Begin
//r_F:=flags[tmp2 and $FF];
        Rflags_a:=(tmp2 and $FF);Rflags;
    r_F:=Rflags_result;
end;
procedure rF3; begin
  //rF3;//r_F:=flags[tmp2];
        Rflags_a:=(tmp2);Rflags;
    r_F:=Rflags_result;
               end;
procedure rF4; begin
//rF4;//    r_F:=flags[0];
    Rflags_a:=(0);Rflags;
    r_F:=Rflags_result;
 end;
procedure rF5; begin
//rF5; r_F:=flags[r_A] or (r_F and f_A);
 Rflags_a:=(r_A);Rflags;
    r_F:=(Rflags_result or (r_F and f_A));
end;
procedure clp4;begin clock:=clock+4; end;



begin
r_A:=integer(rgA);r_b:=integer(rgB);r_c:=integer(rgC);r_d:=integer(rgD);
r_e:=integer(rgE);r_H:=integer(rgH);r_L:=integer(rgL);r_F:=integer(rgF);
r_PC:=integer(rgPC);r_SP:=integer(rgSP);

f_S:=integer(fS);f_Z:=integer(fZ);f_5:=integer(f5);f_A:=integer(fA);
f_3:=integer(f3);f_P:=integer(fP);f_1:=integer(f1);f_C:=integer(fC);

  clock:=0; tmp1:=0;  tmp2:=0;  tmp3:=0;  //бнулим :-)
 while (clock < nb_cycles) do
 begin
  opcode:=do_read(r_PC);

case opcode of         // анализируем текущий код 00 .. FF, меняем значение clock в зависимоти от "длинны" команды ...
                       // прыгаем по памяти, меняем значения регистров и портов  ПРОЦ РАБОТАЕТ !!!!
  $00:
  begin
    clp4;
    r_PC:=r_PC+1;
  end;
  $F3:
  begin
    clp4;
    r_PC:=r_PC+1;
  end;
  $FB:
  begin
    clp4;
    r_PC:=r_PC+1;
  end;

  $01:
  begin
    r_B:=do_read(r_PC+2);
    r_C:=do_read(r_PC+1);
    clock:=clock+10;
    r_PC:=r_PC+3;
  end;
  
  $02: 
  begin
    do_write2(r_C,r_B,r_A);
    clock:=clock+7;
    r_PC:=r_PC+1;
  end;

  $03:
  begin
    r_C:=r_C+1;
    if (r_C>$FF) then
    begin
      r_C:=0;
      r_B:=r_B+1;
      if (r_B>$FF) then
      begin
        r_B:=0;
      end;
    end;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;

  $04:
  begin
    tmp2:=((r_B+1) and $FF);
    RF1;
    if (((tmp2 xor r_B) and $10)<>0) then
    begin
      r_F:=r_F or f_A;
    end;
    r_B:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $05: 
  begin
    tmp2:=((r_B-1) and $FF);
    RF1;

    if (((tmp2 xor r_B) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_B:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $06: 
  begin
    r_B:=do_read(r_PC+1);
    clock:=clock+7;
    r_PC:=r_PC+2;
  end;
  
  $07: 
  begin
    r_A:=r_A SHL 1;
    if (r_A>$FF) then
    begin
      r_A:=r_A or 1;
      r_F:=r_F or f_C;
      r_A:= r_A and $FF;
    end
    else
    begin
      r_F:=(r_F and  (not f_C));
    end;
    clp4;
    r_PC:=r_PC+1;
  end;
  $08:  begin
           begin
           clp4;
           r_PC:=r_PC+1;
           end; end;
  $10:  begin
           begin
           clp4;
           r_PC:=r_PC+1;
           end; end;
  $18:  begin
           begin
           clp4;
           r_PC:=r_PC+1;
           end; end;
  $20:  begin
           begin
           clp4;
           r_PC:=r_PC+1;
           end; end;
  $28:  begin
           begin
           clp4;
           r_PC:=r_PC+1;
           end; end;
  $30:  begin
           begin
           clp4;
           r_PC:=r_PC+1;
           end; end;
  $38:
  begin

           begin
           clp4;
           r_PC:=r_PC+1;
           end;
  end;
  
  $09: 
  begin
    r_L:=r_L+r_C;
    r_H:=r_H+r_B;
    if (r_L>$FF) then
    begin
      inc(r_H);
      r_L:=(r_L and $FF);
    end;
    if (r_H>$FF) then
    begin
      r_H:=(r_H and $FF);
      r_F:=(r_F or f_C);
    end
    else
    begin
      r_F:=(r_F and (not f_C));
    end;
    clock:=clock+10;
    r_PC:=r_PC+1;
  end;
  
  $0A: 
  begin
    r_A:=do_read2(r_C,r_B);
    clock:=clock+7;
    r_PC:=r_PC+1;
  end;

  $0B: 
  begin
    r_C:=r_C-1;
    if (r_C<0) then
    begin
      r_C:=$FF;
      r_B:=r_B-1;
      if (r_B<0) then
      begin
        r_B:=$FF;
      end;
    end;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $0C: 
  begin
    tmp2:=((r_C+1) and $FF);
    RF1;
    if (((tmp2 xor r_C) and $10)<>0) then
    begin
      r_F:=r_F or f_A;
    end;
    r_C:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;

  $0D:
  begin
    tmp2:=((r_C-1) and $FF);
    RF1;

    if (((tmp2 xor r_C) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_C:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $0E: 
  begin
    r_C:=do_read(r_PC+1);
    clock:=clock+7;
    r_PC:=r_PC+2;
  end;
  
  $0F: 
  begin
    tmp1:=(r_A and 1);
    r_A:=(r_A shr 1);
    if (tmp1<>0) then
    begin
      r_A:=(r_A or $80);
      r_F:=(r_F or f_C);
    end
    else
    begin
      r_F:=(r_F and ( not f_C));
    end;
    clp4;
    r_PC:=r_PC+1;
  end;
  
  $11: 
  begin
    r_D:=do_read(r_PC+2);
    r_E:=do_read(r_PC+1);
    clock:=clock+10;
    r_PC:=r_PC+3;
  end;
  
  $12: 
  begin
    do_write2(r_E,r_D,r_A);
    clock:=clock+7;
    r_PC:=r_PC+1;
  end;
  
  $13: 
  begin
    r_E:=r_E+1;
    if (r_E>$FF) then
    begin
      r_E:=0;
      r_D:=r_D+1;
      if (r_D>$FF) then
      begin
        r_D:=0;
      end;
    end;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $14: 
  begin
    tmp2:=((r_D+1)and $FF);
    RF1;
    
    if (((tmp2 xor r_D) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_D:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $15: 
  begin
    tmp2:=((r_D-1)and $FF);
    RF1;
    
    if (((tmp2 xor r_D) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_D:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $16: 
  begin
    r_D:=do_read(r_PC+1);
    clock:=clock+7;
    r_PC:=r_PC+2;
  end;
  
  $17: 
  begin
    r_A:=(r_A shl 1);

    if ((r_F and f_C)<>0) then 
    begin
      r_A:=(r_A or 1);
    end;
    
    if (r_A>$FF) then 
    begin
      r_F:=(r_F or f_C);
      r_A:=(r_A and $FF);
    end else begin
      r_F:=(r_F and (not f_C));
    end;
    clp4;
    r_PC:=r_PC+1;
  end;
  
  $19: 
  begin
    r_L:=(r_L + r_E);
    r_H:=(r_H + r_D);
    
    if (r_L>$FF) then 
    begin
      inc(r_H);
      r_L:=(r_L and $FF);
    end;

    if (r_H>$FF) then 
    begin
      r_H:=(r_H and $FF);
      r_F:=(r_F or f_C);
    end
    else
    begin
      r_F:=(r_F and not (f_C));
    end;
    clock:=clock+10;
    r_PC:=r_PC+1;
  end;
  
  $1A: 
  begin
    r_A:=do_read2(r_E,r_D);
    clock:=clock+7;
    r_PC:=r_PC+1;
  end;
  
  $1B: 
  begin
    r_E:=r_E-1;
    if (r_E<0) then
    begin
      r_E:=$FF;
      r_D:=r_D-1;
      if (r_D<0) then
      begin
        r_D:=$FF;
      end;
    end;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $1C: 
  begin
    tmp2:=((r_E+1)and $FF);
    RF1;

    if (((tmp2 xor r_E) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_E:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $1D: 
  begin
    tmp2:=((r_E-1) and $FF);
    RF1;

    if (((tmp2 xor r_E) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_E:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $1E: 
  begin
    r_E:=do_read(r_PC+1);
    clock:=clock+7;
    r_PC:=r_PC+2;
  end;
  
  $1F: 
  begin
    tmp1:=(r_A and 1);
    r_A:=(r_A SHR 1);
    
    if ((r_F and f_C)<>0) then
    begin
      r_A:=(r_A or $80);
    end;

    if (tmp1<>0) then
    begin
      r_F:=(r_F or f_C);
    end
    else
    begin
      r_F:=(r_F and not(f_C));
    end;
    clp4;
    r_PC:=r_PC+1;
  end;

  $21:
  begin
    r_H:=do_read(r_PC+2);
    r_L:=do_read(r_PC+1);
    clock:=clock+10;
    r_PC:=r_PC+3;
  end;

  $22: 
  begin
    tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
    do_write(tmp1,r_L);
    do_write(tmp1+1,r_H);
    clock:=clock+16;
    r_PC:=r_PC+3;
  end;
  
  $23: 
  begin
    r_L:=r_L+1;
    if (r_L>$FF) then
    begin
      r_L:=0;
      r_H:=r_H+1;
      if (r_H>$FF) then
      begin
        r_H:=0;
      end;
    end;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $24: 
  begin
    tmp2:=((r_H+1) and $FF);
    RF1;
    if (((tmp2 xor r_H) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_H:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $25: 
  begin
    tmp2:=((r_H-1) and $FF);
    RF1;
    if (((tmp2 xor r_H) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_H:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $26: 
  begin
    r_H:=do_read(r_PC+1);
    clock:=clock+7;
    r_PC:=r_PC+2;
  end;
  
  $27: 
  begin
    tmp1:=0;
    if (((r_F and f_C)<>0) or  (r_A>$99)) then
    begin
      tmp1:=(tmp1 or $60);
    end;
    if (((r_F and f_A)<>0)    or  ((r_A and $0F)>$09)) then
    begin
      tmp1:=(tmp1 or $06);
    end;
    tmp2:=r_A+tmp1;
    RF2;
    if (((tmp2 xor r_A xor tmp1) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    if (tmp2>$FF) then
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clp4;
    r_PC:=r_PC+1;
  end;
  
  $29: 
  begin
    r_L:=r_L + r_L;
    r_H:=r_H + r_H;
    
    if (r_L>$FF) then 
    begin
      inc(r_H);
      r_L:=(r_L and $FF);
    end;
    if (r_H>$FF) then
    begin
      r_H:=(r_H and $FF);
      r_F:=(r_F or f_C);
    end else begin
      r_F:=(r_F and (not f_C));
    end;
    clock:=clock+10;
    r_PC:=r_PC+1;
  end;
  
  $2A: 
  begin
    tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
    r_L:=do_read(tmp1);
    r_H:=do_read(tmp1+1);
    clock:=clock+16;
    r_PC:=r_PC+3;
  end;
  
  $2B: 
  begin
    r_L:=r_L-1;
    if (r_L <0) then
    begin
      r_L:=$FF;
      r_H:=r_H-1;
      if (r_H<0) then
      begin
        r_H:=$FF;
      end;
    end;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $2C: 
  begin
    tmp2:=((r_L+1) and $FF);
    RF1;
    if (((tmp2 xor r_L) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_L:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $2D: 
  begin
    tmp2:=((r_L-1) and $FF);
    RF1;
    if (((tmp2 xor r_L) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_L:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $2E: 
  begin
    r_L:=do_read(r_PC+1);
    clock:=clock+7;
    r_PC:=r_PC+2;
  end;
  
  $2F: 
  begin
    r_A:=(r_A xor $FF);
    clp4;
    r_PC:=r_PC+1;
  end;
  
  $31: 
  begin
    r_SP:=(do_read(r_PC+2) shl 8)+do_read(r_PC+1);
    clock:=clock+10;
    r_PC:=r_PC+3;
  end;
  
  $32: 
  begin
    do_write2(do_read(r_PC+1),do_read(r_PC+2),r_A);
    clock:=clock+13;
    r_PC:=r_PC+3;
  end;
  
  $33: 
  begin
    if (r_SP=$FFFF) then
    begin
      r_SP:=0;
    end
    else
    begin
      inc(r_SP);
    end;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $34: 
  begin
    tmp1:=do_read2(r_L,r_H);
    tmp2:=((tmp1+1)  and $FF);
RF1;

    if (((tmp2 xor tmp1) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    do_write2(r_L,r_H,tmp2);
    clock:=clock+10;
    r_PC:=r_PC+1;
  end;
  
  $35: 
  begin
    tmp1:=do_read2(r_L,r_H);
    tmp2:=((tmp1-1) and $FF);
    RF1;


    if (((tmp2 xor tmp1) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    do_write2(r_L,r_H,tmp2);
    clock:=clock+10;
    r_PC:=r_PC+1;
  end;

  $36:
  begin
    do_write2(r_L,r_H,do_read(r_PC+1));
    clock:=clock+10;
    r_PC:=r_PC+2;
  end;

  $37:
  begin
    r_F:=(r_F or f_C);
    clp4;
    r_PC:=r_PC+1;
  end;
  
  $39: 
  begin
    r_L:=(r_L + (r_SP and $FF));
    r_H:=(r_H + ((r_SP shr 8) and $FF));
    if (r_L>$FF) then
    begin
      inc(r_H);
      r_L:=(r_L and $FF);
    end;
    if (r_H>$FF) then 
    begin
      r_H:=(r_H and $FF);
      r_F:=(r_F or f_C);
    end else begin
      r_F:=(r_F and (not f_C));
    end;
    clock:=clock+10;
    r_PC:=r_PC+1;
  end;
  
  $3A: 
  begin
    r_A:=do_read2(do_read(r_PC+1),do_read(r_PC+2));
    clock:=clock+13;
    r_PC:=r_PC+3;
  end;
  
  $3B: 
  begin
    if (r_SP<>0) then 
    begin
      r_SP:=r_SP-1;
    end
    else
    begin
      r_SP:=$FFFF;
    end;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $3C: 
  begin
    tmp2:=((r_A+1) and $FF);
    RF1;
    if (((tmp2 xor r_A) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;

  $3D:
  begin
    tmp2:=((r_A-1) and $FF);
    RF1;
    if (((tmp2 xor r_A) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $3E: 
  begin
    r_A:=do_read(r_PC+1);
    clock:=clock+7;
    r_PC:=r_PC+2;
    
  end;
  
  $3F: 
  begin
    r_F:=r_F xor f_C;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $40:  begin clock:=clock+5;    r_PC:=r_PC+1; end;
  $49:  begin clock:=clock+5;    r_PC:=r_PC+1; end;
  $52:  begin clock:=clock+5;    r_PC:=r_PC+1; end;
  $5B:  begin clock:=clock+5;    r_PC:=r_PC+1; end;
  $64:  begin clock:=clock+5;    r_PC:=r_PC+1; end;
  $6D:  begin clock:=clock+5;    r_PC:=r_PC+1; end;
  $7F:
  begin
    clock:=clock+5;    r_PC:=r_PC+1;
  end;

  $41:
  begin
    r_B:=r_C;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;

  $42:
  begin
    r_B:=r_D;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $43: 
  begin
    r_B:=r_E;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $44: 
  begin
    r_B:=r_H;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $45: 
  begin
    r_B:=r_L;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $46: 
  begin
    r_B:=do_read2(r_L,r_H);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $47: 
  begin
    r_B:=r_A;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $48: 
  begin
    r_C:=r_B;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $4A: 
  begin
    r_C:=r_D;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $4B: 
  begin
    r_C:=r_E;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $4C: 
  begin
    r_C:=r_H;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $4D: 
  begin
    r_C:=r_L;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $4E: 
  begin
    r_C:=do_read2(r_L,r_H);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $4F: 
  begin
    r_C:=r_A;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $50: 
  begin
    r_D:=r_B;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $51: 
  begin
    r_D:=r_C;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $53: 
  begin
    r_D:=r_E;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $54: 
  begin
    r_D:=r_H;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $55: 
  begin
    r_D:=r_L;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $56: 
  begin
    r_D:=do_read2(r_L,r_H);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $57: 
  begin
    r_D:=r_A;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $58: 
  begin
    r_E:=r_B;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $59: 
  begin
    r_E:=r_C;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $5A: 
  begin
    r_E:=r_D;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $5C: 
  begin
    r_E:=r_H;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $5D: 
  begin
    r_E:=r_L;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $5E: 
  begin
    r_E:=do_read2(r_L,r_H);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $5F: 
  begin
    r_E:=r_A;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $60: 
  begin
    r_H:=r_B;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $61: 
  begin
    r_H:=r_C;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $62: 
  begin
    r_H:=r_D;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $63: 
  begin
    r_H:=r_E;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $65: 
  begin
    r_H:=r_L;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $66: 
  begin
    r_H:=do_read2(r_L,r_H);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $67: 
  begin
    r_H:=r_A;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $68: 
  begin
    r_L:=r_B;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $69: 
  begin
    r_L:=r_C;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $6A: 
  begin
    r_L:=r_D;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $6B: 
  begin
    r_L:=r_E;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $6C: 
  begin
    r_L:=r_H;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $6E: 
  begin
    r_L:=do_read2(r_L,r_H);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $6F: 
  begin
    r_L:=r_A;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $70: 
  begin
    do_write2(r_L,r_H,r_B);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $71: 
  begin
    do_write2(r_L,r_H,r_C);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $72: 
  begin
    do_write2(r_L,r_H,r_D);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $73: 
  begin
    do_write2(r_L,r_H,r_E);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $74: 
  begin
    do_write2(r_L,r_H,r_H);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $75: 
  begin
    do_write2(r_L,r_H,r_L);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $76: 
  begin
   // cpu_halt_state:=true;
   // cpu_halt_reason:=halt_hlt;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $77: 
  begin
    do_write2(r_L,r_H,r_A);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $78: 
  begin
    r_A:=r_B;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $79: 
  begin
    r_A:=r_C;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $7A: 
  begin
    r_A:=r_D;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $7B: 
  begin
    r_A:=r_E;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $7C: 
  begin
    r_A:=r_H;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $7D: 
  begin
    r_A:=r_L;
    clock:=clock+5;
    r_PC:=r_PC+1;
    
  end;
  
  $7E: 
  begin
    r_A:=do_read2(r_L,r_H);
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $80: 
  begin
    tmp2:=r_A+r_B;
    RF2;
    
    if (((tmp2  xor r_A  xor r_B) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=(tmp2 and $FF);
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $81: 
  begin
    tmp2:=r_A+r_C;
    RF2;
    
    if (((tmp2  xor r_A  xor r_C) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $82: 
  begin
    tmp2:=r_A+r_D;
    RF2;
    
    if (((tmp2  xor r_A  xor r_D) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $83: 
  begin
    tmp2:=r_A+r_E;
    RF2;
    
    if (((tmp2  xor r_A  xor r_E) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $84: 
  begin
    tmp2:=r_A+r_H;
    RF2;
    
    if (((tmp2  xor r_A  xor r_H) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $85: 
  begin
    tmp2:=r_A+r_L;
    RF2;
    
    if (((tmp2  xor r_A  xor r_L) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $86: 
  begin
    tmp1:=do_read2(r_L,r_H);
    tmp2:=r_A+tmp1;
    RF2;
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $87: 
  begin
    tmp2:=r_A+r_A;
    RF2;
    
    if (((tmp2  xor r_A  xor r_A) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $88: 
  begin
    tmp2:=r_A+r_B;
    if ((r_F and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
    RF2;
    
    if (((tmp2  xor r_A  xor r_B) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $89: 
  begin
    tmp2:=r_A+r_C;
    if ((r_F and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
    RF2;
    
    if (((tmp2  xor r_A  xor r_C) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $8A: 
  begin
    tmp2:=r_A+r_D;
    if ((r_F and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
    RF2;
    
    if (((tmp2  xor r_A  xor r_D) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $8B: 
  begin
    tmp2:=r_A+r_E;
    if ((r_F and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
    RF2;
    
    if (((tmp2  xor r_A  xor r_E) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $8C: 
  begin
    tmp2:=r_A+r_H;
    if ((r_F and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
    RF2;
    
    if (((tmp2  xor r_A  xor r_H) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=r_F or f_C;
    end;
    r_A:=tmp2 and $FF;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $8D: 
  begin
    tmp2:=r_A+r_L;
    if ((r_F and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
    RF2;
    
    if (((tmp2  xor r_A  xor r_L) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $8E: 
  begin
    tmp1:=do_read2(r_L,r_H);
    tmp2:=r_A+tmp1;
    if ((r_F and f_C)<>0) then  tmp2:=tmp2+1 else tmp2:=tmp2+0;
    RF2;
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $8F: 
  begin
    tmp2:=r_A+r_A;
    if ((r_F and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
    RF2;

    if (((tmp2  xor r_A  xor r_A) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;

    if (tmp2>$FF) then
    begin
      r_F:=(r_F or f_C);
    end;
    r_A:=tmp2 and $FF;
    clp4;
    r_PC:=r_PC+1;
    
  end;

17

SOURCE_DELPHI\002\
uMain.pas part2

Код:
 
  $90: 
  begin
    tmp2:=(r_A-r_B) and $FF;
    RF3;

    if (r_A<r_B) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_B) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $91: 
  begin
    tmp2:=(r_A-r_C) and $FF;
    RF3;

    
    if (r_A<r_C) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_C) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $92: 
  begin
    tmp2:=(r_A-r_D) and $FF;
    RF3;

    if (r_A<r_D) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_D) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $93: 
  begin
    tmp2:=(r_A-r_E) and $FF;
    RF3;
    
    if (r_A<r_E) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_E) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $94: 
  begin
    tmp2:=(r_A-r_H) and $FF;
    RF3;
    
    if (r_A<r_H) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_H) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $95: 
  begin
    tmp2:=(r_A-r_L) and $FF;
    RF3;
    
    if (r_A<r_L) then 
    begin
      r_F:=r_F or f_C;
    end;
    
    if (((tmp2  xor r_A  xor r_L) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $96: 
  begin
    tmp1:=do_read2(r_L,r_H);
    tmp2:=(r_A-tmp1) and $FF;
    RF3;
    
    if (r_A<tmp1) then 
    begin
      r_F:=(r_F or f_C);
    end;

    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+7;
    r_PC:=r_PC+1;

  end;

  $97:
  begin
    rF4;
    r_A:=0;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $98: 
  begin
    if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
    tmp2:=(r_A-r_B-tmp3) and $FF;
    RF3;
    
    if (r_A<r_B+tmp3) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_B) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $99: 
  begin
    if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
    tmp2:=(r_A-r_C-tmp3) and $FF;
    RF3;
    
    if (r_A<(r_C+tmp3)) then
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_C) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $9A: 
  begin
    if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
    tmp2:=(r_A-r_D-tmp3) and $FF;
    RF3;
    
    if (r_A<r_D+tmp3) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_D) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $9B: 
  begin
    if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
    tmp2:=(r_A-r_E-tmp3) and $FF;
    RF3;
    
    if (r_A<r_E+tmp3) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_E) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $9C: 
  begin
    if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
    tmp2:=(r_A-r_H-tmp3) and $FF;
    RF3;

    if (r_A<r_H+tmp3) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_H) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $9D: 
  begin
    if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
    tmp2:=(r_A-r_L-tmp3) and $FF;
    RF3;

    if (r_A<r_L+tmp3) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_L) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $9E: 
  begin
    tmp1:=do_read2(r_L,r_H);
    if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
    tmp2:=(r_A-tmp1-tmp3) and $FF;
    RF3;
    
    if (r_A<tmp1+tmp3) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    r_A:=tmp2;
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $9F: 
  begin
    if ((r_F and f_C)<>0) then tmp2:=$FF else tmp2:=0;
    RF3;
    
    if (tmp2<>0) then 
    begin
      r_F:=r_F or (f_A or f_C);
    end;
    r_A:=tmp2;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $A0: 
  begin
    r_A:=r_A and r_B;
rF5;

    clp4;
    r_PC:=r_PC+1;
    
  end;

  $A1: 
  begin
    r_A:=r_A and r_C;
    rF5;

    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $A2: 
  begin
    r_A:=r_A and r_D;
rF5;

    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $A3: 
  begin
    r_A:=r_A and r_E;
rF5;

    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $A4: 
  begin
    r_A:=r_A and r_H;
rf5;

    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $A5: 
  begin
    r_A:=r_A and r_L;
    RF5;

    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $A6: 
  begin
    tmp1:=do_read2(r_L,r_H);
    r_A:=r_A and tmp1;
    RF5;
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $A7: 
  begin
    r_A:=r_A and r_A;
    RF5;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $A8: 
  begin
    r_A:=r_A xor r_B;
    RF5;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $A9: 
  begin
    r_A:=r_A  xor r_C;
    RF5;
    clp4;
    r_PC:=r_PC+1;

  end;

  $AA:
  begin
    r_A:=r_A xor r_D;
    RF5;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $AB: 
  begin
    r_A:=r_A  xor r_E;
    RF5;
    clp4;
    r_PC:=r_PC+1;

  end;

  $AC:
  begin
    r_A:=r_A  xor r_H;
    RF5;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $AD: 
  begin
    r_A:=r_A  xor r_L;
    RF5;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $AE: 
  begin
    tmp1:=do_read2(r_L,r_H);
    r_A:=r_A xor tmp1;
    RF5;
    clock:=clock+7;
    r_PC:=r_PC+1;

  end;

  $AF:
  begin
    r_A:=0;
    RF5;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $B0: 
  begin
    r_A:=r_A or r_B;
    RF5;
    clp4;
    r_PC:=r_PC+1;

  end;

  $B1:
  begin
    r_A:=r_A or r_C;
    RF5;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $B2: 
  begin
    r_A:=r_A or r_D;
    RF5;
    clp4;
    r_PC:=r_PC+1;

  end;

  $B3:
  begin
    r_A:=r_A or r_E;
    RF5;
    clp4;
    r_PC:=r_PC+1;

  end;

  $B4:
  begin
    r_A:=r_A or r_H;
    RF5;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $B5: 
  begin
    r_A:=r_A or r_L;
    RF5;
    clp4;
    r_PC:=r_PC+1;

  end;

  $B6:
  begin
    tmp1:=do_read2(r_L,r_H);
    r_A:=r_A or tmp1;
    RF5;
    clock:=clock+7;
    r_PC:=r_PC+1;

  end;

  $B7:
  begin
    r_A:=r_A or r_A;
    RF5;
    clp4;
    r_PC:=r_PC+1;

  end;

  $B8:
  begin
    tmp2:=(r_A-r_B) and $FF;
    RF3;

    if (r_A<r_B) then
    begin
      r_F:=(r_F or f_C);
    end;

    if (((tmp2  xor r_A  xor r_B) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    clp4;
    r_PC:=r_PC+1;

  end;

  $B9:
  begin
    tmp2:=(r_A-r_C) and $FF;
    RF3;

    if (r_A<r_C) then
    begin
      r_F:=(r_F or f_C);
    end;

    if (((tmp2  xor r_A  xor r_C) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    clp4;
    r_PC:=r_PC+1;

  end;

  $BA:
  begin
    tmp2:=(r_A-r_D) and $FF;
    RF3;

    if (r_A<r_D) then
    begin
      r_F:=(r_F or f_C);
    end;

    if (((tmp2  xor r_A  xor r_D) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    clp4;
    r_PC:=r_PC+1;

  end;

  $BB:
  begin
    tmp2:=(r_A-r_E) and $FF;
    RF3;

    if (r_A<r_E) then
    begin
      r_F:=(r_F or f_C);
    end;

    if (((tmp2  xor r_A  xor r_E) and $10)<>0) then
    begin
      r_F:=(r_F or f_A);
    end;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $BC: 
  begin
    tmp2:=(r_A-r_H) and $FF;
    RF3;
    
    if (r_A<r_H) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_H) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $BD: 
  begin
    tmp2:=(r_A-r_L) and $FF;
    RF3;
    
    if (r_A<r_L) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor r_L) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $BE: 
  begin
    tmp1:=do_read2(r_L,r_H);
    tmp2:=(r_A-tmp1) and $FF;
    RF3;
    
    if (r_A<tmp1) then 
    begin
      r_F:=(r_F or f_C);
    end;
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=(r_F or f_A);
    end;
    clock:=clock+7;
    r_PC:=r_PC+1;
    
  end;
  
  $BF:
  begin
    rf4;

    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $C0: 
  begin
    
    if ((r_F and f_Z)<>0) then
     begin
      clock:=clock+5;
      r_PC:=r_PC+1;
     end
        else
     begin
      r_PC:=do_read(r_SP);
      r_PC:=r_PC+(do_read(r_SP+1) shl 8);
      r_SP:=(r_SP+2) and $FFFF;
      clock:=clock+11;
     end;
  end;

  $C1:
  begin
    r_C:=do_read(r_SP);
    r_B:=do_read(r_SP+1);
    r_SP:=(r_SP+2) and $FFFF;
    clock:=clock+10;
    r_PC:=r_PC+1;

  end;

  $C2:
  begin

    if ((r_F and f_Z)<>0) then
    begin
      clock:=clock+10;
      r_PC:=r_PC+3;
    end
    else
    begin
      r_PC:=do_read(r_PC+1)+((do_read(r_PC+2) shl 8));
      clock:=clock+10;
    end;
  end;

  $C3:
  begin
    r_PC:=do_read(r_PC+1)+((do_read(r_PC+2) shl 8));
    clock:=clock+10;
  end;

  $C4:
  begin
    if ((r_F and f_Z)<>0) then
    begin
      clock:=clock+11;
      r_PC:=r_PC+3;
    end
        else
        begin
      tmp1:=do_read(r_PC+1)+((do_read(r_PC+2) shl 8));
      r_SP:=(r_SP-2) and $FFFF;
      r_PC:=r_PC+3;
      do_write(r_SP,r_PC and $FF);
      do_write(r_SP+1,(r_PC shr 8) and $FF);
      r_PC:=tmp1;
      clock:=clock+17;

    end;
  end;

  $C5:
  begin
    r_SP:=(r_SP-2) and $FFFF;
    do_write(r_SP,r_C);
    do_write(r_SP+1,r_B);
    clock:=clock+11;
    r_PC:=r_PC+1;

  end;

  $C6:
  begin
    tmp1:=do_read(r_PC+1);
    tmp2:=r_A+tmp1;
    RF2;

    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then
    begin
      r_F:=r_F or f_A;
    end;

    if (tmp2>$FF) then
    begin
      r_F:=r_F or f_C;
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+7;
    r_PC:=r_PC+2;

  end;

  $C7:
  begin
    r_SP:=(r_SP-2) and $FFFF;
    inc(r_PC);
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=0*8;
    clock:=clock+11;

  end;

  $C8:
  begin

    if ((r_F and f_Z)=0) then

    begin
      clock:=clock+5;
      r_PC:=r_PC+1;
    end
        else
    begin

      r_PC:=do_read(r_SP);
      r_PC:=r_PC+(do_read(r_SP+1) shl 8);
      r_SP:=(r_SP+2) and $FFFF;
      clock:=clock+11;

    end;
  end;
  
  $C9: 
  begin
    r_PC:=do_read(r_SP);
    r_PC:=r_PC+(do_read(r_SP+1) shl 8);
    r_SP:=(r_SP+2) and $FFFF;
    clock:=clock+11;
    
  end;
  
  $CA: 
  begin
    
    if ((r_F and f_Z)=0) then
    begin
      clock:=clock+10;
      r_PC:=r_PC+3;
    end
        else
    begin
      r_PC:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      clock:=clock+10;

    end;

  end;
  
  $CB: 
  begin

           begin
            r_PC:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
            clock:=clock+10;
           end;
    
  end;
  
  $CC: 
  begin
    
    if ((r_F and f_Z)=0) then
    begin
      clock:=clock+11;
      r_PC:=r_PC+3;
    end
    else
    begin
      tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      r_SP:=(r_SP-2) and $FFFF;
      r_PC:=r_PC+3;
      do_write(r_SP,r_PC and $FF);
      do_write(r_SP+1,(r_PC shr 8) and $FF);
      r_PC:=tmp1;
      clock:=clock+17;
    end
  end;
  
  $CD: 
  begin
    tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
    r_SP:=(r_SP-2) and $FFFF;
    r_PC:=r_PC+3;
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=tmp1;
    clock:=clock+17;
    
  end;
  
  $CE: 
  begin
    tmp1:=do_read(r_PC+1);
    tmp2:=r_A+tmp1;
    if ((r_F and f_C)<>0) then tmp2:=tmp2+1 else  tmp2:=tmp2+0;
    RF2;
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=r_F or f_A;
    end;
    
    if (tmp2>$FF) then 
    begin
      r_F:=r_F or f_C;
    end;
    r_A:=tmp2 and $FF;
    clock:=clock+7;
    r_PC:=r_PC+2;
    
  end;
  
  $CF: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    inc(r_PC);
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=1*8;
    clock:=clock+11;
    
  end;
  
  $D0: 
  begin
    
    if ((r_F and f_C)<>0) then
    begin
      clock:=clock+5;
      r_PC:=r_PC+1;
    end
     else
     begin
      r_PC:=do_read(r_SP);
      r_PC:=r_PC+(do_read(r_SP+1) shl 8);
      r_SP:=(r_SP+2) and $FFFF;
      clock:=clock+11;
    end
  end;
  
  $D1: 
  begin
    r_E:=do_read(r_SP);
    r_D:=do_read(r_SP+1);
    r_SP:=(r_SP+2) and $FFFF;
    clock:=clock+10;
    r_PC:=r_PC+1;
    
  end;
  
  $D2: 
  begin
    if ((r_F and f_C)<>0) then

    begin
      clock:=clock+10;
      r_PC:=r_PC+3;
    end
     else
    begin
      r_PC:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      clock:=clock+10;
    end;
  end;
  
  $D3: 
  begin
    do_output(do_read(r_PC+1),r_A);
    clock:=clock+10;
    r_PC:=r_PC+2;
    
  end;
  
  $D4: 
  begin
    
    if ((r_F and f_C)<>0) then
   
    begin
      clock:=clock+11;
      r_PC:=r_PC+3;
    end
     else
    begin
      tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      r_SP:=(r_SP-2) and $FFFF;
      r_PC:=r_PC+3;
      do_write(r_SP,r_PC and $FF);
      do_write(r_SP+1,(r_PC shr 8) and $FF);
      r_PC:=tmp1;
      clock:=clock+17;
    end;
  end;
  
  $D5: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    do_write(r_SP,r_E);
    do_write(r_SP+1,r_D);
    clock:=clock+11;
    r_PC:=r_PC+1;
    
  end;
  
  $D6: 
  begin
    tmp1:=do_read(r_PC+1);
    tmp2:=(r_A-tmp1) and $FF;
    RF3;
    
    if (r_A<tmp1) then 
    begin
      r_F:=r_F or f_C;
    end;
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=r_F or f_A;
    end;
    r_A:=tmp2;
    clock:=clock+7;
    r_PC:=r_PC+2;
    
  end;
  
  $D7: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    inc(r_PC);
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=2*8;
    clock:=clock+11;
    
  end;
  
  $D8: 
  begin
    
    if ((r_F and f_C)=0) then
    begin
      clock:=clock+5;
      r_PC:=r_PC+1;
    end
    else
    begin
      r_PC:=do_read(r_SP);
      r_PC:=r_PC+do_read(r_SP+1) shl 8;
      r_SP:=(r_SP+2) and $FFFF;
      clock:=clock+11;
    end;
  end;
  
  $D9: 
  begin

           begin
            r_PC:=do_read(r_SP);
            r_PC:=r_PC+do_read(r_SP+1) shl 8;
            r_SP:=(r_SP+2) and $FFFF;
            clock:=clock+11;
           end;
    
  end;
  
  $DA: 
  begin
    
    if ((r_F and f_C)=0) then
    begin
      clock:=clock+10;
      r_PC:=r_PC+3;
    end
     else
    begin
      r_PC:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      clock:=clock+10;
    end;
  end;
  
  $DB: 
  begin
    r_A:=do_input(do_read(r_PC+1));
    clock:=clock+10;
    r_PC:=r_PC+2;
    
  end;
  
  $DC: 
  begin
    
    if ((r_F and f_C)=0) then
    begin
      clock:=clock+11;
      r_PC:=r_PC+3;
    end
    else
    begin
      tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      r_SP:=(r_SP-2) and $FFFF;
      r_PC:=r_PC+3;
      do_write(r_SP,r_PC and $FF);
      do_write(r_SP+1,(r_PC shr 8) and $FF);
      r_PC:=tmp1;
      clock:=clock+17;
    end;
  end;
  
  $DD:    begin

    begin
    tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
    r_SP:=(r_SP-2) and $FFFF;
    r_PC:=r_PC+3;
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=tmp1;
    clock:=clock+17;
    end;
  end;


  $ED:    begin

    begin
    tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
    r_SP:=(r_SP-2) and $FFFF;
    r_PC:=r_PC+3;
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=tmp1;
    clock:=clock+17;
    end;
  end;


  $FD:
  begin

    begin
    tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
    r_SP:=(r_SP-2) and $FFFF;
    r_PC:=r_PC+3;
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=tmp1;
    clock:=clock+17;
    end;
  end;

  $DE: 
  begin
    tmp1:=do_read(r_PC+1);
    if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
    tmp2:=(r_A-tmp1-tmp3) and $FF;
    RF3;
    
    if (r_A<tmp1+tmp3) then 
    begin
      r_F:=r_F or f_C;
    end;
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=r_F or f_A;
    end;
    r_A:=tmp2;
    clock:=clock+7;
    r_PC:=r_PC+2;
    
  end;
  
  $DF: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    inc(r_PC);
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=3*8;
    clock:=clock+11;
    
  end;
  
  $E0: 
  begin
    if ((r_F and f_P)<>0) then
    begin
      clock:=clock+5;
      r_PC:=r_PC+1;
    end
    else
    begin
      r_PC:=do_read(r_SP);
      r_PC:=r_PC+do_read(r_SP+1) shl 8;
      r_SP:=(r_SP+2) and $FFFF;
      clock:=clock+11;
    end ;
    
  end;
  
  $E1: 
  begin
    r_L:=do_read(r_SP);
    r_H:=do_read(r_SP+1);
    r_SP:=(r_SP+2) and $FFFF;
    clock:=clock+10;
    r_PC:=r_PC+1;
    
  end;
  
  $E2: 
  begin
    
    if ((r_F and f_P)<>0) then
    
    begin
      clock:=clock+10;
      r_PC:=r_PC+3;
    end
    else
    begin
      r_PC:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      clock:=clock+10;

    end;
    
  end;
  
  $E3: 
  begin
    tmp1:=do_read(r_SP);
    do_write(r_SP,r_L);
    r_L:=tmp1;
    tmp1:=do_read(r_SP+1);
    do_write(r_SP+1,r_H);
    r_H:=tmp1;
    clock:=clock+18;
    r_PC:=r_PC+1;
    
  end;
  
  $E4: 
  begin
    
    if ((r_F and f_P)<>0) then
    
    begin
      clock:=clock+11;
      r_PC:=r_PC+3;
    end
    else
    begin
      tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      r_SP:=(r_SP-2) and $FFFF;
      r_PC:=r_PC+3;
      do_write(r_SP,r_PC and $FF);
      do_write(r_SP+1,(r_PC shr 8) and $FF);
      r_PC:=tmp1;
      clock:=clock+17;

    end;
    
  end;
  
  $E5: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    do_write(r_SP,r_L);
    do_write(r_SP+1,r_H);
    clock:=clock+11;
    r_PC:=r_PC+1;
    
  end;
  
  $E6: 
  begin
    r_A:=r_A and do_read(r_PC+1);
    RF5;
    clock:=clock+7;
    r_PC:=r_PC+2;
  end;
  
  $E7: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    inc(r_PC);
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=4*8;
    clock:=clock+11;
    
  end;
  
  $E8: 
  begin
    if ((r_F and f_P)=0) then
    begin
      clock:=clock+5;
      r_PC:=r_PC+1;
    end
     else
    begin
      r_PC:=do_read(r_SP);
      r_PC:=r_PC+do_read(r_SP+1) shl 8;
      r_SP:=(r_SP+2) and $FFFF;
      clock:=clock+11;

    end;
    
  end;
  
  $E9: 
  begin
    r_PC:=(r_H shl 8)+r_L;
    clock:=clock+5;
  end;
  
  $EA: 
  begin
    
    if ((r_F and f_P)=0) then
    begin
      clock:=clock+10;
      r_PC:=r_PC+3;  
    end
    else
    begin
      r_PC:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      clock:=clock+10;

    end;
  end;
  
  $EB: 
  begin
    tmp1:=r_D;
    r_D:=r_H;
    r_H:=tmp1;
    tmp1:=r_E;
    r_E:=r_L;
    r_L:=tmp1;
    clp4;
    r_PC:=r_PC+1;
    
  end;
  
  $EC: 
  begin
    if ((r_F and f_P)=0) then
    begin
      clock:=clock+11;
      r_PC:=r_PC+3;
    end
    else
    begin
      tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      r_SP:=(r_SP-2) and $FFFF;
      r_PC:=r_PC+3;
      do_write(r_SP,r_PC and $FF);
      do_write(r_SP+1,(r_PC shr 8) and $FF);
      r_PC:=tmp1;
      clock:=clock+17;
    end;
  end;
  
  $EE: 
  begin
    r_A:= r_A xor do_read(r_PC+1);
    RF5;
    clock:=clock+7;
    r_PC:=r_PC+2;
  end;
  
  $EF: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    inc(r_PC);
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=5*8;
    clock:=clock+11;
  end;
  
  $F0: 
  begin
    if ((r_F and f_S)<>0) then
     begin
      clock:=clock+5;
      r_PC:=r_PC+1;
     end
     else
     begin
      r_PC:=do_read(r_SP);
      r_PC:=r_PC+(do_read(r_SP+1) shl 8);
      r_SP:=(r_SP+2) and $FFFF;
      clock:=clock+11;
    end;
  end;
  
  $F1: 
  begin
    r_F:=do_read(r_SP);
    r_A:=do_read(r_SP+1);
    r_SP:=(r_SP+2) and $FFFF;
    clock:=clock+10;
    r_PC:=r_PC+1;
  end;
  
  $F2: 
  begin
    if ((r_F and f_S)<>0) then
    begin
      clock:=clock+10;
      r_PC:=r_PC+3;
    end
    else
    begin
      r_PC:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      clock:=clock+10;
    end;
  end;
  
  $F4: 
  begin
    
    if ((r_F and f_S)<>0) then
    begin
      clock:=clock+11;
      r_PC:=r_PC+3;
    end
    else
    begin
      tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      r_SP:=(r_SP-2) and $FFFF;
      r_PC:=r_PC+3;
      do_write(r_SP,r_PC and $FF);
      do_write(r_SP+1,(r_PC shr 8) and $FF);
      r_PC:=tmp1;
      clock:=clock+17;
    end;
  end;
  
  $F5: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    do_write(r_SP,r_F);
    do_write(r_SP+1,r_A);
    clock:=clock+11;
    r_PC:=r_PC+1;
    
  end;
  
  $F6: 
  begin
    r_A:=r_A or do_read(r_PC+1);
    RF5;
    clock:=clock+7;
    r_PC:=r_PC+2;
    
  end;
  
  $F7: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    inc(r_PC);
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=6*8;
    clock:=clock+11;
    
  end;
  
  $F8: 
  begin
    if ((r_F and f_S)=0) then
    begin
      clock:=clock+5;
      r_PC:=r_PC+1;
    end
     else
    begin
      r_PC:=do_read(r_SP);
      r_PC:=r_PC+(do_read(r_SP+1) shl 8);
      r_SP:=(r_SP+2) and $FFFF;
      clock:=clock+11;

    end;
  end;
  
  $F9: 
  begin
    r_SP:=(r_H shl 8)+r_L;
    clock:=clock+5;
    r_PC:=r_PC+1;
  end;
  
  $FA: 
  begin
    if ((r_F and f_S)=0) then
    begin
      clock:=clock+10;
      r_PC:=r_PC+3;
    end
     else
    begin
      r_PC:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      clock:=clock+10;
    end;
  end;
  
  $FC: 
  begin
    if ((r_F and f_S)=0) then
    begin
      clock:=clock+11;
      r_PC:=r_PC+3;
    end
    else
    begin
      tmp1:=do_read(r_PC+1)+(do_read(r_PC+2) shl 8);
      r_SP:=(r_SP-2) and $FFFF;
      r_PC:=r_PC+3;
      do_write(r_SP,r_PC and $FF);
      do_write(r_SP+1,(r_PC shr 8) and $FF);
      r_PC:=tmp1;
      clock:=clock+17;
    end;
  end;
  
  $FE: 
  begin
    tmp1:=do_read(r_PC+1);
    tmp2:=(r_A-tmp1) and $FF;
    RF3;

    if (r_A<tmp1) then
    begin
      r_F:=r_F or f_C;
    end;
    
    if (((tmp2  xor r_A  xor tmp1) and $10)<>0) then 
    begin
      r_F:=r_F or f_A;
    end;
    clock:=clock+7;
    r_PC:=r_PC+2;

  end;
  
  $FF: 
  begin
    r_SP:=(r_SP-2) and $FFFF;
    inc(r_PC);
    do_write(r_SP,r_PC and $FF);
    do_write(r_SP+1,(r_PC shr 8) and $FF);
    r_PC:=7*8;
    clock:=clock+11;

  end
  else
  begin
     // cpu_halt_state:=true;
     // cpu_halt_reason:=halt_inv;
  end;

end;
end;
rgA:=Cardinal(r_A);rgB:=Cardinal(r_b);rgC:=Cardinal(r_c);rgD:=Cardinal(r_d);
rgE:=Cardinal(r_e);rgH:=Cardinal(r_H);rgL:=Cardinal(r_L);rgF:=Cardinal(r_F);
rgPC:=Cardinal(r_PC);rgSP:=Cardinal(r_SP);

fS:=Cardinal(f_S);fZ:=Cardinal(f_Z);f5:=Cardinal(f_5);fA:=Cardinal(f_A);
f3:=Cardinal(f_3);fP:=Cardinal(f_P);f1:=Cardinal(f_1);fC:=Cardinal(f_C);
end;


procedure TMainForm.draw_screen;   //Рисуем с video на экран  (Форму)

var
  i,vertX,gorY : word;
begin
  i:=0;
  vertX:=0;
  gorY:=0;
  while (i<$4000) do
  begin
   if video[i]<>VideoDirty[i] then //сравниваем значения , а есть ли изменения
        begin
          //WriteVRAM(video[i],vertX,gorY);   //старый способ каждый раз расчет шел
        //if not N7.Checked then  // черно белое ТВ
          begin
          gamecanvas.Canvas.Pixels[vertX,gorY]:=  SuperColor[ports[$C1],video[i],1];
          gamecanvas.Canvas.Pixels[vertX+1,gorY]:=SuperColor[ports[$C1],video[i],2];
          gamecanvas.Canvas.Pixels[vertX+2,gorY]:=SuperColor[ports[$C1],video[i],3];
          gamecanvas.Canvas.Pixels[vertX+3,gorY]:=SuperColor[ports[$C1],video[i],4];
          end;


        end;
    vertX:=vertX+4;
    if vertX>=256 then begin vertX:=0; gorY:=gorY+1; end;
    inc(i);
  end;
{$R-}
for I := 0 to $4000 do VideoDirty[i]:= video[i];  // быстрое копирование массивов
{$R+}
//if FullScreen1.Checked then                        // на весь экран или нет
MainForm.Canvas.StretchDraw(rect(0,0,MainForm.Width-0,MainForm.Height-30), gamecanvas)
//else
//MainForm.Canvas.Draw(0,0,gamecanvas);
end;


procedure TMainForm.VRAMTest(c1,b:Byte);

Var

pix1,pix2,pix3,pix4:byte;
begin
   pix1:=0; pix2:=0; pix3:=0; pix4:=0;
  if (b and 128)=128 then pix1:=pix1+1;
  if (b and 8)=8     then pix1:=pix1+2;
  if (b and 64)=64   then pix2:=pix2+1;
  if (b and 4)=4     then pix2:=pix2+2;
  if (b and 32)=32   then pix3:=pix3+1;
  if (b and 2)=2     then pix3:=pix3+2;
  if (b and 16)=16   then pix4:=pix4+1;
  if (b and 1)=1     then pix4:=pix4+2;

  SuperColor[c1,b,1]:=compute_color_index(c1,Mycolor[pix1]);

  SuperColor[c1,b,2]:=compute_color_index(c1,Mycolor[pix2]);

  SuperColor[c1,b,3]:=compute_color_index(c1,Mycolor[pix3]);

  SuperColor[c1,b,4]:=compute_color_index(c1,Mycolor[pix4]);

end;

procedure TMainForm.CalculateColor;
var
  I,j: Integer;
begin
for I := 0 to 255 do
   for j := 0 to 255 do
    begin
       VRAMTest(i, j);
    end;
end;


function TMainForm.compute_color_index(port : byte; color : tcolor): tcolor;  // колор в зависимоти от порта С

begin
  Result:=ClBLACK;
  if ((port and $40)<>0) then Result:= (Result xor ClBLUE);
  if ((port and $20)<>0) then Result:= (Result xor clLime);
  if ((port and $10)<>0) then Result:= (Result xor ClRED);
  case color of
  clBLACK:
     begin
       if ((port and $08)=0) then
         begin
           Result:= (Result xor CLRED);
         end;
       if ((port and $04)=0) then
         begin
          Result:= (Result xor ClBLUE);
         end;
      end;
   clLime: begin
      Result:= (Result xor clLime);
      end;
   clred:  begin
       Result:= (Result xor ClRED);
       if ((port and $02)=0) then
           begin
             //Result:= (Result xor ClGREEN);
             Result:= (Result xor clLime);
           end;
        end;
    clBLUE: begin
         Result:= (Result xor ClBLUE);
         if ((port and $01)=0) then
            begin
             Result:= (Result xor ClRED);
            end;
       end;
end;
   // result:= ((Result and $07) shl 13) or ((Result and $38) shl 5) or ((Result and $C0) shr 3);
end;



procedure TMainForm.WriteVRAM(b:Byte;x,y: integer);  // рисуем на gamecanvas значения цвета , не забываем про порт С1

Var
pix1,pix2,pix3,pix4:byte;
begin
  pix1:=0; pix2:=0; pix3:=0; pix4:=0;        //вычисляем цвет в зависимисти от установки бит
  if (b and 128)=128 then pix1:=pix1+1;
  if (b and 8)=8     then pix1:=pix1+2;
  if (b and 64)=64   then pix2:=pix2+1;
  if (b and 4)=4     then pix2:=pix2+2;
  if (b and 32)=32   then pix3:=pix3+1;
  if (b and 2)=2     then pix3:=pix3+2;
  if (b and 16)=16   then pix4:=pix4+1;
  if (b and 1)=1     then pix4:=pix4+2;



    begin
     gamecanvas.Canvas.Pixels[x,y]:=  compute_color_index(ports[$C1],Mycolor[pix1]);
     gamecanvas.Canvas.Pixels[x+1,y]:=compute_color_index(ports[$C1],Mycolor[pix2]);
     gamecanvas.Canvas.Pixels[x+2,y]:=compute_color_index(ports[$C1],Mycolor[pix3]);
     gamecanvas.Canvas.Pixels[x+3,y]:=compute_color_index(ports[$C1],Mycolor[pix4]);
     end;
end;



procedure TMainForm.FirstPusk; //первый запуск
 begin
 // создадим канву для рисования
 gamecanvas:=tbitmap.Create;
 gamecanvas.Width:=256;
 gamecanvas.Height:=256;

  ResetComp; // первоночальный сброс всего
  TimerMain.Enabled:=true; // запускаем основной таймер
end;

function TMainForm.readmask (keynum: word): word;    // маска клавы
begin
result:= $72FF;
case keynum of
      8: begin result:= $23FF end;  // BCK
     13: begin result:= $13FF end;  // ENTER
	   16: begin result:= $70FF end;  // SHIFT
     32: begin result:= $30FF end;  // SPC

     37: begin result:= $FF32 end;  //  <-
     38: begin result:= $FF31 end;  //  UP
     39: begin result:= $FF30 end;  //  ->
     40: begin result:= $FF33 end;  //  DOWN

     48: begin result:= $06FF end;  //   0
	   49: begin result:= $47FF end;  //   1
	   50: begin result:= $46FF end;  //   2
   	 51: begin result:= $45FF end;  //   3
  	 52: begin result:= $44FF end;  //   4
   	 53: begin result:= $43FF end;  //   5
   	 54: begin result:= $00FF end;  //   6
  	 55: begin result:= $01FF end;  //   7
  	 56: begin result:= $02FF end;  //   8
  	 57: begin result:= $07FF end;  //   9

  	 65: begin result:= $64FF end;  //   A
     66: begin result:= $31FF end;  //   B
     67: begin result:= $57FF end;  //   C
     68: begin result:= $27FF end;  //   D
     69: begin result:= $54FF end;  //   E
     70: begin result:= $67FF end;  //   F
     71: begin result:= $10FF end;  //   G
  	 72: begin result:= $16FF end;  //   H
  	 73: begin result:= $75FF end;  //   I
  	 74: begin result:= $52FF end;  //   J
     75: begin result:= $55FF end;  //   K
   	 76: begin result:= $22FF end;  //   L
  	 77: begin result:= $76FF end;  //   M
  	 78: begin result:= $53FF end;  //   N
   	 79: begin result:= $21FF end;  //   O
   	 80: begin result:= $63FF end;  //   P
  	 81: begin result:= $71FF end;  //   Q
     82: begin result:= $20FF end;  //   R
   	 83: begin result:= $77FF end;  //   S
   	 84: begin result:= $74FF end;  //   T
     85: begin result:= $56FF end;  //   U
  	 86: begin result:= $26FF end;  //   V
  	 87: begin result:= $65FF end;  //   W
   	 88: begin result:= $73FF end;  //   X
   	 89: begin result:= $66FF end;  //   Y
  	 90: begin result:= $17FF end;  //   Z

  	 107: begin result:= $05FF end;  //   =/+ -> =/-
  	 109: begin result:= $05FF end;  //   -/_ -> =/-

  	 114: begin result:= $FF23 end;  // F3
  	 115: begin result:= $FF22 end;  // F4
   	 116: begin result:= $FF21 end;  // F5

  	 36: begin result:= $FF20 end;  // Home

  	 219: begin result:= $11FF end;  //   [
  	 221: begin result:= $12FF end;  //   ]
  	 190: begin result:= $24FF end;  //   .
   	 188: begin result:= $37FF end;  //   ,
   	 192: begin result:= $72FF end;  //
end;

end;

procedure TMainForm.FormActivate(Sender: TObject);
begin
if FPusk then    // а это первый ли запуск
    begin
    FPusk:=false;
    FirstPusk;
    end;
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
DragAcceptFiles(MainForm.Handle, true);   // сделаем драг анд дроб :)
CalculateColor;
FPusk:=true; // запомним первый запуск
English1Click(Sender);
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin
DragAcceptFiles(Handle, False);

end;

procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;  //опрос клавы
  Shift: TShiftState);
begin
    kbd(readmask(key),true);  // нажали
    i8080_do_opcodes(opcodes_to_run);
end;

procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
   kbd(readmask(key),false); // отпустии
end;

procedure TMainForm.TimerMainTimer(Sender: TObject);  // основной таймер
var
j,a: word;
i: integer;
s: string;
begin
if (pause) then  // если пауза курим бамбук :)
  begin
    exit;
  end;
 i8080_do_opcodes(opcodes_to_run);
 draw_screen;

end;

procedure TMainForm.ResetComp;
begin
 rgB := 0; rgC := 0; rgD := 0; rgE := 0; rgH := 0; rgL := 0; rgA := 0; rgF := 0;
 rgPC := 0; rgSP := 0;
// clock := 0; // обнулим часики

 halt_inv := 1;
 halt_opc := 2;
 halt_hlt := 3;

 halt_bpx := 4;
 halt_bpr := 5;
 halt_bpw := 6;
 halt_bpi := 7;
 halt_bpo := 8;



 pause := false;
 FPS := 50;


 speaked := 0;

 fS := (1 SHL 7);
 fZ :=( 1 SHL 6);
 f5 := (1 SHL 5);
 fA := (1 SHL 4);
 f3 := (1 SHL 3);
 fP := (1 SHL 2);
 f1 := (1 SHL 1);
 fC := (1 SHL 0);

 BasicStack := $AFC1;
 BasicHotEntry := $02FD;
 BasicProgBegin := $0243;
 BasicProgEnd := $0245;


  fillchar(VideoDirty,sizeof(VideoDirty),257);

  soundEnabled := false;
 // opcodes_to_run := round ((1411200*4)/FPS);
  opcodes_to_run := round ((1411200*2)/FPS);
  curSnd := 0;
  restClock := 0;
  init_memory();
  reset1();
  load_bios();
  i8080_do_opcodes(0);
end;

procedure TMainForm.ResetCPU1Click(Sender: TObject);
begin
ResetComp;
end;





procedure TMainForm.English1Click(Sender: TObject);
begin


MainForm.Caption:='PK-01 Lvov emulator';

//DebuggerForm.TabSheet1.Caption:='Assembler';
//DebuggerForm.TabSheet2.Caption:='Find-replace in memory';


N1.Caption:='File';
N2.Caption:='Open';
ResetCPU1.Caption:='Reset CPU';
N11.Caption:='Pause';
N4.Caption:='Exit';





end;

procedure TMainForm.Russian1Click(Sender: TObject);
begin


MainForm.Caption:='ПК-01 Львов эмулятор';

//DebuggerForm.TabSheet1.Caption:='Ассемблер';
//DebuggerForm.TabSheet2.Caption:='Поиск-замена в памяти';

N1.Caption:='Файл';
N2.Caption:='Открыть';
ResetCPU1.Caption:='Reset CPU';
N11.Caption:='Пауза';
N4.Caption:='Выход';

end;


// ###################################################ГРЕБАННЫЙ ЗВУК :-) ##############################################################


end.

18

SOURCE_DELPHI\003\
EmulForKOS.dpr

Код:
program EmulForKOS;

uses
  Forms,
  Windows,
  uMain in 'uMain.pas' {MainForm};

{$R *.res}

begin
  SetThreadLocale(1049);
  Application.Initialize;
  Application.Title := 'ой кэбнб';
  Application.CreateForm(TMainForm, MainForm);
  Application.Run;
end.

19

SOURCE_DELPHI\003\
uMain.pas

Код:
unit uMain;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Menus,MMSystem,ShellAPI, ImgList, ComCtrls,
  ToolWin;
type
  TMainForm = class(TForm)
    TimerMain: TTimer;    MainMenu1: TMainMenu;
    N1: TMenuItem;    N2: TMenuItem;   N3: TMenuItem;    N4: TMenuItem;
    OpenDialogLvt: TOpenDialog;
    ResetCPU1: TMenuItem;
    N11: TMenuItem;
    procedure fillcharVideoDirty;
    procedure draw_screen1;
    procedure draw_screen2;
    Procedure SupCol2;
    Procedure My_col2;
    procedure col_index;
    procedure TimerMainTimer(Sender: TObject);
    procedure do_write(addr: Cardinal; bt: Cardinal);
    procedure i8080_init;
    function  do_read(addr: Cardinal): Cardinal;
    procedure do_write2(a_lo: Cardinal; a_hi: Cardinal; bt: Cardinal);
    function  do_read2(a_lo : Cardinal; a_hi : Cardinal): Cardinal;
    procedure init_memory;
    function  do_input(port : Cardinal): Cardinal;
    procedure do_output(port : Cardinal; bt : Cardinal);
    procedure kbd(mask : word; press : boolean);
    procedure reset1;
    procedure load_bios;
    procedure do_pause();
    procedure i8080_do_opcodes(nb_cycles : Cardinal);    //выполнение комманд процессора
    procedure draw_screen();
    procedure FirstPusk;
    function  readmask (keynum: word): word;
    procedure N4Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure NewLoadFile(filenameDnD: string;start : boolean);
    procedure ResetComp;
    procedure ResetCPU1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Wmemory;    procedure Rmemory;
    procedure Wflags;     procedure Rflags;
    procedure Wvideo;     procedure Rvideo;
    procedure WVideoDirty;    procedure RVideoDirty;
    procedure Wports;    procedure Rports;
    procedure Wkbd_base;    procedure Rkbd_base;
    procedure Wkbd_ext;    procedure Rkbd_ext;
  private
    { Private declarations }
  public
    procedure WMDropFiles(var Msg: TMessage); message wm_DropFiles;
    { Public declarations }
  end;

var
  MainForm: TMainForm;
  var { регистрики}   rgA,rgB,rgC,rgD,rgE,rgH,rgL,rgF,rgPC,rgSP :Cardinal;
  var { флаги}   fS, fZ, f5, fA, f3,fP,f1,fC : Cardinal;
  memoryM: array [0..65535] of byte;  // массив основной памяти $FFFF
  videoM : array [0..16384] of byte;  // видео память
  VideoDirtyM : array [0..16384] of word; //буфер для быстрой прорисовки
  flagsM: array [0..256] of  word;
  portsM: array [0..256]   of byte;      // порты
  kbd_baseM : array  [0..8] of byte;  // массивы опроса клавиатуры
  kbd_extM : array  [0..4] of byte;
    FPusk: boolean; // первый запуск
    gamecanvas: tbitmap; // сюда все рисуем перед выводом на форму

    bios  : array [0..65535] of byte;    // массив для загрузки биоса, можно сразу грузить но вдруг пригодися
    Myfile: array [0..90000] of byte; //файл может быть большим DUMP SAV который

    pause : boolean; //пауза в эмуляторе
//    opcodes_to_run:Cardinal = round ((1411200*2)/50{FPS});
//   FPS:Cardinal=50;   opcodes_to_run:Cardinal = 68500;
   FPS:Cardinal=1000;   opcodes_to_run:Cardinal = 68500;
  myfilelength: Cardinal; // длина скачаного файла

  BasicStack,BasicHotEntry,BasicProgBegin,BasicProgEnd : Cardinal;

var   LVColBlack:Cardinal=0; LVColLime:Cardinal=$00FF00; LVColBlue:Cardinal=$FF0000; LVColRed:Cardinal=$0000FF;
implementation
{$R *.dfm}
var Wmemory_a,Wmemory_b:Cardinal; procedure TMainForm.Wmemory; begin memoryM[Wmemory_a]:=Wmemory_b; end;
var Rmemory_a,Rmemory_result:Cardinal; procedure TMainForm.Rmemory; begin Rmemory_result:=memoryM[Rmemory_a];end;
var Wflags_a,Wflags_b:Cardinal; procedure TMainForm.Wflags; begin flagsM[Wflags_a]:=Wflags_b; end;
var Rflags_a,Rflags_result:Cardinal; procedure TMainForm.Rflags; begin Rflags_result:=flagsM[Rflags_a];end;
var Wvideo_a,Wvideo_b:Cardinal; procedure TMainForm.Wvideo; begin videoM[Wvideo_a]:=Wvideo_b; end;
var Rvideo_a,Rvideo_result:Cardinal; procedure TMainForm.Rvideo; begin Rvideo_result:=videoM[Rvideo_a];end;
var WVideoDirty_a,WVideoDirty_b:Cardinal; procedure TMainForm.WVideoDirty; begin VideoDirtyM[WVideoDirty_a]:=WVideoDirty_b; end;
var RVideoDirty_a,RVideoDirty_result:Cardinal; procedure TMainForm.RVideoDirty; begin RVideoDirty_result:=VideoDirtyM[RVideoDirty_a];end;
var Wports_a,Wports_b:Cardinal; procedure TMainForm.Wports; begin portsM[Wports_a]:=Wports_b; end;
var Rports_a,Rports_result:Cardinal; procedure TMainForm.Rports; begin Rports_result:=portsM[Rports_a];end;
var Wkbd_base_a,Wkbd_base_b:Cardinal; procedure TMainForm.Wkbd_base; begin kbd_baseM[Wkbd_base_a]:=Wkbd_base_b; end;
var Rkbd_base_a,Rkbd_base_result:Cardinal; procedure TMainForm.Rkbd_base; begin Rkbd_base_result:=kbd_baseM[Rkbd_base_a];end;
var Wkbd_ext_a,Wkbd_ext_b:Cardinal; procedure TMainForm.Wkbd_ext; begin kbd_extM[Wkbd_ext_a]:=Wkbd_ext_b; end;
var Rkbd_ext_a,Rkbd_ext_result:Cardinal; procedure TMainForm.Rkbd_ext; begin Rkbd_ext_result:=kbd_extM[Rkbd_ext_a];end;




procedure TMainForm.fillcharVideoDirty;
var c:Cardinal; begin {$R-} For c:=0 to 16384 do begin
Rvideo_a:=c; Rvideo; WVideoDirty_a:=c;WVideoDirty_b:=(Rvideo_result xor 1);WVideoDirty;{$R+} end; end;

procedure TMainForm.WMDropFiles(var Msg: TMessage);   // порцедура отвечает за принятие перетаскиваемого файла
var FileName: array[0..256] of char;
begin DragQueryFile(THandle(Msg.WParam), 0, FileName, SizeOf(Filename));
MainForm.Caption:=FileName;NewLoadFile(FileName,true);DragFinish(THandle(Msg.WParam));end;

procedure TMainForm.do_write(addr : Cardinal; bt : Cardinal); // если нужно будем записывать :-)
begin
 {$R-}
if  addr> $FFFF then addr:=$FFFF;
  if (addr>=$C000) then
  begin    exit;  end;
Rports_a:=$C2;Rports; if ((Rports_result and 2)<>0) then  begin    Wmemory_A:=addr; Wmemory_B:=bt; Wmemory;  end else
if (addr<$4000) then  begin exit; end else
if (addr<$8000) then begin Wvideo_a:=(addr-$4000);Wvideo_b:=bt; Wvideo; end else
begin  Wmemory_A:=addr; Wmemory_B:=bt; Wmemory;    end;
 {$R+}
end;


procedure TMainForm.i8080_init;

var  j,i : Cardinal;
begin
   {$R-}
for i:=0  to 255 do
  begin
 {flags[i]:=f1 or fP;}    Wflags_a:=i;Wflags_b:=(f1 or fP);Wflags;
for j:=0  to 7 do
    begin
       if ((i and (1 SHL j))<>0) then
             begin
        {  flags[i]:=(flags[i] xor fP);}
         Rflags_a:=i;Rflags;
        Wflags_a:=i;Wflags_b:=(Rflags_Result xor fP);Wflags;
             end;
        end;
 if ((i and $80)<>0) then
    begin
            {   flags[i]:=(flags[i] or fS);}
                    Rflags_a:=i;Rflags;
          Wflags_a:=i;Wflags_b:=(Rflags_Result or fS);Wflags;
             end;
       if (i=0) then
             begin
              {  flags[i]:=(flags[i] or fZ);}
                   Rflags_a:=i;Rflags;
          Wflags_a:=i;Wflags_b:=(Rflags_Result or fZ);Wflags;
             end;
  end;
   {$R+}
end;




function TMainForm.do_read(addr : Cardinal): Cardinal; // считаем значение из пямяти
begin
    {$R-}
if  addr> $FFFF then addr:=$FFFF;
RPorts_a:=$C2;RPorts;   if ((RPorts_result and 2)<>0) then
  begin      Rmemory_A:=addr; Rmemory; result := Rmemory_result;  end
  else  if (addr>$7FFF) then  begin     Rmemory_A:=addr; Rmemory; result := Rmemory_result;  end
  else if (addr<$4000) then  begin    result := 0;  end  else
  begin   Rvideo_a:=(addr-$4000); Rvideo; result := Rvideo_result;  end;
    {$R+}
end;

procedure TMainForm.do_write2(a_lo: Cardinal; a_hi: Cardinal; bt: Cardinal);
begin {$R-}  do_write(a_lo+(a_hi SHL 8),bt); {$R+}end;

function TMainForm.do_read2(a_lo : Cardinal; a_hi : Cardinal): Cardinal;
begin {$R-}    result := do_read(a_lo+(a_hi SHL 8)); {$R+}end;


procedure TMainForm.init_memory;    // подготовим все к запуску
var  i : Cardinal;
begin
  {$R-}
//For i:=0 to $FFFF do  begin     Wmemory_A:=i; Wmemory_B:=0; Wmemory;  end;
//For i:=0 to $3FFF do begin    Wvideo_a:=i; Wvideo_b:=0;Wvideo;  end;
//For i:=0 to $FF do begin  Wports_a:=i; Wports_b:=0; Wports;  end;
//For i:=0 to 7 do begin    Wkbd_base_a:=i;Wkbd_base_b:=0;Wkbd_base;  end;
//For i:=0 to 3 do begin    Wkbd_ext_a:=i;Wkbd_ext_b:=0;Wkbd_ext;  end;
i8080_init;
TimerMain.Interval:=(1000 div FPS);
{$R+}
end;


function TMainForm.do_input(port : Cardinal): Cardinal;  // работа со значениями портов in
var   i,r : Cardinal;  nD2 ,nD0 : Cardinal;
begin
    {$R-}
   port:=$C0+(port and $13);
  case port of
  $C2:     begin Rports_a:=$C2;Rports; result := Rports_result; end;
  $D1:     begin Rports_a:=$D0;Rports; nD0:=not Rports_result; r:=0;
             For i:=0 to 7 do
             begin
             if ((nD0 and (1 SHL i))<>0) then begin rkbd_base_a:=i;rkbd_base; r:=(r or Rkbd_base_result); end;
             end;
             result :=  ((not r) and $FF);
           end;
   $D2:    begin Rports_a:=$D2;Rports;  nD2:= not Rports_result; r:=0;
           for i:=0 to 3 do begin if ((nD2 and (1 SHL i))<>0) then begin Rkbd_ext_a:=i;Rkbd_ext; r:=(r or Rkbd_ext_result);end;
              end;
              result := not ((r SHL 4) or (nD2 and $0F)) and $FF;
            end
     else begin result := $FF; end;
end;
  {$R+}
end;

procedure TMainForm.do_output(port : Cardinal; bt : Cardinal); // out
begin
    {$R-}
  port:=$C0+(port and $13);
  case port of
  $c1:  begin // изменение порта цвета
          fillcharVideoDirty;
        end;

  end;
  Wports_a:=port;Wports_b:=bt; Wports;
      {$R+}
end ;

procedure TMainForm.kbd(mask : word; press : boolean); //  по маске вкл выкл клавишу
var  brow : byte;  erow : byte;  bcol : byte;  ecol : byte;
begin
      {$R-}
  bcol:=(mask SHR 12) and $0F;  brow:=(mask SHR 8) and $0F;
  ecol:=(mask SHR 4) and $0F;  erow:=(mask SHR 0) and $0F;
  if ((brow<8) and (bcol<8)) then
  begin
   if (press) then    begin Rkbd_base_a:=bcol;Rkbd_base;
       Wkbd_base_a:=bcol;Wkbd_base_b:=(Rkbd_base_result or (1 SHL brow));Wkbd_base;  end
        else begin Rkbd_base_a:=bcol;Rkbd_base;
           Wkbd_base_a:=bcol;Wkbd_base_b:=(Rkbd_base_result and (not(1 SHL brow))); Wkbd_base;   end;
  end;
  if ((erow<8) and (ecol<4)) then  begin Rkbd_ext_a:=ecol;Rkbd_ext;
  if (press) then    begin      Wkbd_ext_a:=ecol;Wkbd_ext_b:= (Rkbd_ext_result or (1 SHL erow));Wkbd_ext;
    end else begin  Rkbd_ext_a:=ecol;Rkbd_ext;    Wkbd_ext_a:=ecol;Wkbd_ext_b:=(Rkbd_ext_result and (not(1 SHL erow)));Wkbd_ext;   end;
  end;
      {$R+}
end;

procedure TMainForm.reset1;    // полный ресет :)
var  i : word; begin {$R-} for i:=0 to  255 do begin
  Wports_a:=i;Wports_b:=$FF; Wports;  end; {$R+} end;

procedure TMainForm.load_bios;    // загрузка биоса из файла
var i: Cardinal;b: Byte;f: file of byte;
begin
  {$R-}
  i:=0;  AssignFile(F,ExtractFilePath(Application.ExeName)+'\bios.dat');
  Reset(F);  while not eof(f) do   begin    read(F,b);    bios[i]:=b;    inc(i);   end;
  closeFile(F);  i:=0;
 for i:=0 to $3FFF do begin  Wmemory_a:=($C000+i);Wmemory_b:=bios[22+i];Wmemory; end;
    {$R+}
end;

procedure TMainForm.N2Click(Sender: TObject);
begin
  OpenDialogLvt.InitialDir:=ExtractFilePath(Application.ExeName);
  if OpenDialogLvt.Execute then NewLoadFile(OpenDialogLvt.FileName,true);
end;

procedure TMainForm.N4Click(Sender: TObject);
begin gamecanvas.Free;close;end;

procedure TMainForm.NewLoadFile(filenameDnD: string; start : boolean);  //процедура загрузки всех видов файлов
var f:file of byte; b:Byte; s: string; posBas, Xend ,Xbeg ,Xrun : word; i: integer;
begin
    {$R-}
  s:='';
    AssignFile(f,filenameDnD); // распознаем что за файл
      Reset(f);
   for I:= 0 to 8  do    begin      read(f,b);         s:=s+chr(b);        end;
   if s='LVOV/2.0/' then // стандартный LVT файл
      begin         read(f,b);
         if b=$D0 then      { это бинарник}         begin
           seek(F,0); // вернемся к началу файла
           i:=0;
           while not eof(f) do
           begin read(F,b); Myfile[i]:=b; inc(i); end;
           myfilelength:=i;
           closeFile(F);     //закрываем файл
           Xbeg:=Myfile[16]+Myfile[17]*256;           Xend:=Myfile[18]+Myfile[19]*256;
           Xrun:=Myfile[20]+Myfile[21]*256;
          if (start) then  begin {warm_start();} rgPC:=Xrun; end;
           i:=0;
           while (i<=Xend-Xbeg) do begin  do_write(Xbeg+i,Myfile[i+22]); inc(i); end;
         end
              else
         begin      //это бeйсик (надеюсь больше ничего нет :-) )
           seek(F,0); // вернемся к началу файла
           i:=0;
           while not eof(f) do
              begin read(F,b); Myfile[i]:=b; inc(i); end;
            myfilelength:=i-1;            {warm_start();}
//            posBas:=get_var(BasicProgBegin);
            i:=0;      while (i<myfilelength-16) do
               begin do_write(posBas+i,Myfile[i+16]); inc(i); end;
              // направим RUN
              MainForm.SetFocus;
              i8080_do_opcodes(opcodes_to_run);
                 end;
       end;
      if s='LVOV/DUMP' then // стандартный SAV файл дампа эмулятор Калашникова
         begin
           seek(F,0); // вернемся к началу файла
           i:=0;  while not eof(f) do begin read(F,b); Myfile[i]:=b; inc(i);end;
           i:=0;    closeFile(F);
           while (i<$10000) do
         begin{ memory[i]:=Myfile[17+i];} Wmemory_A:=i; Wmemory_B:=Myfile[17+i]; Wmemory;inc(i);end;
           i:=0;       while (i<$4000) do begin
            Wvideo_a:=i;Wvideo_b:=Myfile[17+$10000+i];Wvideo; inc(i); end;
           i:=0;       while (i<$100) do begin

           Wports_a:=i;Wports_b:=Myfile[17+$10000+$4000+i]; Wports;
           inc(i);

            end;
           rgB:=Myfile[17+$10000+$4000+$100];           rgH:=Myfile[17+$10000+$4000+$100+4];
           rgC:=Myfile[17+$10000+$4000+$100+1];           rgL:=Myfile[17+$10000+$4000+$100+5];
           rgD:=Myfile[17+$10000+$4000+$100+2];           rgA:=Myfile[17+$10000+$4000+$100+6];
           rgE:=Myfile[17+$10000+$4000+$100+3];           rgF:=Myfile[17+$10000+$4000+$100+7];
           rgSP:=Myfile[17+$10000+$4000+$100+9]*256+Myfile[17+$10000+$4000+$100+8];
           rgPC:=Myfile[17+$10000+$4000+$100+11]*256+Myfile[17+$10000+$4000+$100+10];
           fillcharVideoDirty;           draw_screen;
         end;
  {$R-}
end;

procedure  TMainForm.do_pause();
begin
	pause := not pause;
end;
   

procedure TMainForm.i8080_do_opcodes(nb_cycles : Cardinal);     //выполнение комманд процессора
var tmp3,  tmp2,  tmp1,  opcode : integer;
var { регистрики}   r_A,r_B,r_C,r_D,r_E,r_H,r_L,r_F,r_PC,r_SP : integer;
clock:Cardinal;
{ флаги}   f_S, f_Z, f_5, f_A, f_3,f_P,f_1,f_C : Integer;
procedure rA1; Begin r_A:=tmp2 and $FF; end;
procedure rA2; Begin r_A:=tmp2; end;

procedure rF1;Begin Rflags_a:=tmp2;Rflags; r_F:=(Rflags_result or (r_F and f_C)); end;
procedure rF2;Begin Rflags_a:=(tmp2 and $FF);Rflags;    r_F:=Rflags_result; end;
procedure rF3;begin Rflags_a:=(tmp2);Rflags; r_F:=Rflags_result; end;
procedure rF4;begin Rflags_a:=(0);Rflags; r_F:=Rflags_result; end;
procedure rF5; begin Rflags_a:=(r_A);Rflags;    r_F:=(Rflags_result or (r_F and f_A)); end;
procedure rF6; begin  r_F:=r_F or f_A;    end;
procedure rF7; begin  r_F:=(r_F or f_C); end;
procedure rF8; begin r_F:=(r_F or f_A); end;

procedure rt2p1; begin tmp2:=tmp2+1 end;
procedure clp4;begin clock:=clock+4; end;
procedure clp7;begin clock:=clock+7; end;
procedure clp5;begin clock:=clock+5; end;
procedure clp10;begin clock:=clock+10; end;
procedure clp11;begin clock:=clock+11; end;
procedure clp13;begin clock:=clock+13; end;
procedure clp16;begin clock:=clock+16; end;
procedure clp17;begin clock:=clock+17; end;

procedure r_PCp1;begin r_PC:=r_PC+1; end;
procedure r_PCp2;begin r_PC:=r_PC+2; end;
procedure r_PCp3;begin r_PC:=r_PC+3; end;
procedure if1; begin if ((r_F and f_C)<>0) then rt2p1 else tmp2:=tmp2+0;end;
procedure clp5_r_PCp1;  begin clp5; r_PCp1;end;
procedure rF5_clp4_r_PCp1; begin rF5; clp4; r_PCp1;end;
procedure clp4_r_PCp1;  begin clp4; r_PCp1; end;
Function d_rdPCp2:Cardinal; begin Result:=do_read(r_PC+2) end;
Function d_rdPCp1:Cardinal; begin Result:=do_read(r_PC+1) end;
procedure clp10_r_PCp3; begin clp10; r_PCp3; end;
procedure clp7_r_PCp1; begin clp7; r_PCp1; end;
procedure if2; begin if (tmp2>$FF) then begin rF7; end; end;
procedure clp7_r_PCp2; begin clp7; r_PCp2; end;
procedure clp10_r_PCp1; begin clp10; r_PCp1; end;
procedure if2_rA1_clp4_r_PCp1;  Begin if2; rA1; clp4_r_PCp1; end;
procedure rA2_clp4_r_PCp1; Begin rA2; clp4_r_PCp1; end;
begin
    {$R-}
r_A:=integer(rgA);r_b:=integer(rgB);r_c:=integer(rgC);r_d:=integer(rgD);
r_e:=integer(rgE);r_H:=integer(rgH);r_L:=integer(rgL);r_F:=integer(rgF);
r_PC:=integer(rgPC);r_SP:=integer(rgSP);

f_S:=integer(fS);f_Z:=integer(fZ);f_5:=integer(f5);f_A:=integer(fA);
f_3:=integer(f3);f_P:=integer(fP);f_1:=integer(f1);f_C:=integer(fC);

  clock:=0; tmp1:=0;  tmp2:=0;  tmp3:=0;  //бнулим :-)
 while (clock < nb_cycles) do
 begin
  opcode:=do_read(r_PC);

case opcode of  // анализируем текущий код 00 .. FF, меняем значение clock в зависимоти от "длинны" команды ...
   // прыгаем по памяти, меняем значения регистров и портов ПРОЦ РАБОТАЕТ !!!!
$00: begin clp4_r_PCp1; end;
$F3: begin clp4_r_PCp1; end;
$FB: begin clp4_r_PCp1; end;
$01: begin r_B:=d_rdPCp2; r_C:=d_rdPCp1; clp10_r_PCp3; end;
$02: begin do_write2(r_C,r_B,r_A); clp7_r_PCp1; end;
$03: begin r_C:=r_C+1; if (r_C>$FF) then begin r_C:=0; r_B:=r_B+1;
 if (r_B>$FF) then begin r_B:=0; end; end; clp5_r_PCp1; end;

$04: begin tmp2:=((r_B+1) and $FF); RF1;
 if (((tmp2 xor r_B) and $10)<>0) then begin rF6; end;
 r_B:=tmp2; clp5_r_PCp1; end;

$05: begin tmp2:=((r_B-1) and $FF); RF1;
 if (((tmp2 xor r_B) and $10)<>0) then begin rF8; end;
 r_B:=tmp2; clp5_r_PCp1; end;

$06: begin r_B:=d_rdPCp1; clp7_r_PCp2; end;

$07: begin r_A:=r_A SHL 1; if (r_A>$FF) then begin r_A:=r_A or 1; r_F:=r_F or f_C; r_A:= r_A and $FF; end
 else begin r_F:=(r_F and (not f_C)); end; clp4_r_PCp1; end;

$08: begin begin clp4_r_PCp1; end; end;
$10: begin begin clp4_r_PCp1; end; end;
$18: begin begin clp4_r_PCp1; end; end;
$20: begin begin clp4_r_PCp1; end; end;
$28: begin begin clp4_r_PCp1; end; end;
$30: begin begin clp4_r_PCp1; end; end;
$38: begin begin clp4_r_PCp1; end; end;
$09: begin r_L:=r_L+r_C; r_H:=r_H+r_B; if (r_L>$FF) then
 begin inc(r_H); r_L:=(r_L and $FF); end;
 if (r_H>$FF) then begin r_H:=(r_H and $FF); rF7;
 end else begin r_F:=(r_F and (not f_C)); end; clp10_r_PCp1; end;

$0A: begin r_A:=do_read2(r_C,r_B); clp7_r_PCp1; end;

$0B: begin r_C:=r_C-1; if (r_C<0) then begin r_C:=$FF; r_B:=r_B-1;
 if (r_B<0) then begin r_B:=$FF; end; end; clp5_r_PCp1; end;

$0C: begin tmp2:=((r_C+1) and $FF); RF1; if (((tmp2 xor r_C) and $10)<>0) then
 begin rF6; end; r_C:=tmp2; clp5_r_PCp1; end;

$0D: begin tmp2:=((r_C-1) and $FF); RF1; if (((tmp2 xor r_C) and $10)<>0) then
 begin rF8; end; r_C:=tmp2; clp5_r_PCp1; end;

$0E: begin r_C:=d_rdPCp1; clp7_r_PCp2; end;

$0F: begin tmp1:=(r_A and 1); r_A:=(r_A shr 1); if (tmp1<>0) then
 begin r_A:=(r_A or $80); rF7; end else
 begin r_F:=(r_F and ( not f_C)); end; clp4_r_PCp1; end;

$11: begin r_D:=d_rdPCp2; r_E:=d_rdPCp1; clp10_r_PCp3; end;

$12: begin do_write2(r_E,r_D,r_A); clp7_r_PCp1; end;

$13: begin r_E:=r_E+1; if (r_E>$FF) then begin r_E:=0; r_D:=r_D+1;
 if (r_D>$FF) then begin r_D:=0; end; end; clp5_r_PCp1; end;

$14: begin tmp2:=((r_D+1)and $FF); RF1; if (((tmp2 xor r_D) and $10)<>0) then
 begin rF8; end; r_D:=tmp2; clp5_r_PCp1; end;

$15: begin tmp2:=((r_D-1)and $FF); RF1; if (((tmp2 xor r_D) and $10)<>0) then
 begin rF8; end; r_D:=tmp2; clp5_r_PCp1; end;

$16: begin r_D:=d_rdPCp1; clp7_r_PCp2; end;

$17: begin r_A:=(r_A shl 1); if ((r_F and f_C)<>0) then
 begin r_A:=(r_A or 1); end; if (r_A>$FF) then begin rF7;
 r_A:=(r_A and $FF); end else begin r_F:=(r_F and (not f_C)); end;
 clp4_r_PCp1; end;

$19: begin r_L:=(r_L + r_E); r_H:=(r_H + r_D); if (r_L>$FF) then
 begin inc(r_H); r_L:=(r_L and $FF); end;
 if (r_H>$FF) then begin r_H:=(r_H and $FF); rF7;
 end else begin r_F:=(r_F and not (f_C)); end;
 clp10_r_PCp1; end;

$1A: begin r_A:=do_read2(r_E,r_D); clp7_r_PCp1; end;

$1B: begin r_E:=r_E-1; if (r_E<0) then begin r_E:=$FF; r_D:=r_D-1;
 if (r_D<0) then begin r_D:=$FF; end; end; clp5_r_PCp1; end;

$1C: begin tmp2:=((r_E+1)and $FF); RF1; if (((tmp2 xor r_E) and $10)<>0) then
 begin rF8; end; r_E:=tmp2; clp5_r_PCp1; end;

$1D: begin tmp2:=((r_E-1) and $FF); RF1; if (((tmp2 xor r_E) and $10)<>0) then
 begin rF8; end; r_E:=tmp2; clp5_r_PCp1; end;

$1E: begin r_E:=d_rdPCp1; clp7_r_PCp2; end;

$1F: begin tmp1:=(r_A and 1); r_A:=(r_A SHR 1); if ((r_F and f_C)<>0) then
 begin r_A:=(r_A or $80); end; if (tmp1<>0) then begin rF7; end
 else begin r_F:=(r_F and not(f_C)); end; clp4_r_PCp1; end;

$21: begin r_H:=d_rdPCp2; r_L:=d_rdPCp1; clp10_r_PCp3; end;

$22: begin tmp1:=d_rdPCp1+(d_rdPCp2 shl 8); do_write(tmp1,r_L);
 do_write(tmp1+1,r_H); clp16; r_PCp3; end;

$23: begin r_L:=r_L+1; if (r_L>$FF) then begin r_L:=0; r_H:=r_H+1;
 if (r_H>$FF) then begin r_H:=0; end; end; clp5_r_PCp1; end;

$24: begin tmp2:=((r_H+1) and $FF); RF1; if (((tmp2 xor r_H) and $10)<>0) then
 begin rF8; end; r_H:=tmp2; clp5_r_PCp1; end;

$25: begin tmp2:=((r_H-1) and $FF); RF1; if (((tmp2 xor r_H) and $10)<>0) then
 begin rF8; end; r_H:=tmp2; clp5_r_PCp1; end;

$26: begin r_H:=d_rdPCp1; clp7_r_PCp2; end;

$27: begin tmp1:=0; if (((r_F and f_C)<>0) or (r_A>$99)) then
 begin tmp1:=(tmp1 or $60); end;
 if (((r_F and f_A)<>0) or ((r_A and $0F)>$09)) then begin tmp1:=(tmp1 or $06); end;
 tmp2:=r_A+tmp1; RF2; if (((tmp2 xor r_A xor tmp1) and $10)<>0) then
 begin rF8; end; if2;
 rA1; clp4_r_PCp1; end;

$29: begin r_L:=r_L + r_L; r_H:=r_H + r_H; if (r_L>$FF) then begin
 inc(r_H); r_L:=(r_L and $FF); end; if (r_H>$FF) then begin
 r_H:=(r_H and $FF); rF7; end else begin
 r_F:=(r_F and (not f_C)); end; clp10_r_PCp1; end;

$2A: begin tmp1:=d_rdPCp1+(d_rdPCp2 shl 8);
 r_L:=do_read(tmp1); r_H:=do_read(tmp1+1); clp16; r_PCp3; end;

$2B: begin r_L:=r_L-1; if (r_L <0) then begin r_L:=$FF; r_H:=r_H-1;
 if (r_H<0) then begin r_H:=$FF; end; end; clp5; r_PCp1; end;

$2C: begin tmp2:=((r_L+1) and $FF); RF1; if (((tmp2 xor r_L) and $10)<>0) then
 begin rF8; end; r_L:=tmp2; clp5_r_PCp1; end;

$2D: begin tmp2:=((r_L-1) and $FF); RF1; if (((tmp2 xor r_L) and $10)<>0) then
 begin rF8; end; r_L:=tmp2; clp5_r_PCp1; end;

$2E: begin r_L:=d_rdPCp1; clp7_r_PCp2; end;

$2F: begin r_A:=(r_A xor $FF); clp4_r_PCp1; end;

$31: begin r_SP:=(d_rdPCp2 shl 8)+d_rdPCp1; clp10_r_PCp3; end;

$32: begin do_write2(d_rdPCp1,d_rdPCp2,r_A); clp13; r_PCp3; end;

$33: begin if (r_SP=$FFFF) then begin r_SP:=0; end else
 begin inc(r_SP); end; clp5_r_PCp1; end;

$34: begin tmp1:=do_read2(r_L,r_H); tmp2:=((tmp1+1) and $FF);RF1;
 if (((tmp2 xor tmp1) and $10)<>0) then begin rF8; end;
 do_write2(r_L,r_H,tmp2); clp10_r_PCp1; end;

$35: begin tmp1:=do_read2(r_L,r_H); tmp2:=((tmp1-1) and $FF); RF1;
 if (((tmp2 xor tmp1) and $10)<>0) then begin rF8; end;
 do_write2(r_L,r_H,tmp2); clp10_r_PCp1; end;

$36: begin do_write2(r_L,r_H,d_rdPCp1); clp10; r_PCp2; end;

$37: begin rF7; clp4_r_PCp1; end;

$39: begin r_L:=(r_L + (r_SP and $FF)); r_H:=(r_H + ((r_SP shr 8) and $FF));
 if (r_L>$FF) then begin inc(r_H); r_L:=(r_L and $FF); end;
 if (r_H>$FF) then begin r_H:=(r_H and $FF); rF7;
 end else begin r_F:=(r_F and (not f_C)); end; clp10_r_PCp1; end;

$3A: begin r_A:=do_read2(d_rdPCp1,d_rdPCp2); clp13; r_PCp3; end;

$3B: begin if (r_SP<>0) then begin r_SP:=r_SP-1; end else begin r_SP:=$FFFF; end;
 clp5_r_PCp1; end;

$3C: begin tmp2:=((r_A+1) and $FF); RF1; if (((tmp2 xor r_A) and $10)<>0) then
 begin rF8; end; rA2; clp5_r_PCp1; end;

$3D: begin tmp2:=((r_A-1) and $FF); RF1; if (((tmp2 xor r_A) and $10)<>0) then
begin rF8; end; rA2; clp5_r_PCp1; end;

$3E: begin r_A:=d_rdPCp1; clp7_r_PCp2; end;

$3F: begin r_F:=r_F xor f_C; clp4_r_PCp1; end;

$40: begin clp5_r_PCp1; end;
$49: begin clp5_r_PCp1; end;
$52: begin clp5_r_PCp1; end;
$5B: begin clp5_r_PCp1; end;
$64: begin clp5_r_PCp1; end;
$6D: begin clp5_r_PCp1; end;
$7F: begin clp5_r_PCp1; end;
$41: begin r_B:=r_C; clp5_r_PCp1; end;
$42: begin r_B:=r_D; clp5_r_PCp1; end;
$43: begin r_B:=r_E; clp5_r_PCp1; end;
$44: begin r_B:=r_H; clp5_r_PCp1; end;
$45: begin r_B:=r_L; clp5_r_PCp1; end;
$46: begin r_B:=do_read2(r_L,r_H); clp7_r_PCp1; end;
$47: begin r_B:=r_A; clp5_r_PCp1; end;
$48: begin r_C:=r_B; clp5_r_PCp1; end;
$4A: begin r_C:=r_D; clp5_r_PCp1; end;
$4B: begin r_C:=r_E; clp5_r_PCp1; end;
$4C: begin r_C:=r_H; clp5_r_PCp1; end;
$4D: begin r_C:=r_L; clp5_r_PCp1; end;
$4E: begin r_C:=do_read2(r_L,r_H); clp7_r_PCp1; end;
$4F: begin r_C:=r_A; clp5_r_PCp1; end;
$50: begin r_D:=r_B; clp5_r_PCp1; end;
$51: begin r_D:=r_C; clp5_r_PCp1; end;
$53: begin r_D:=r_E; clp5_r_PCp1; end;
$54: begin r_D:=r_H; clp5_r_PCp1; end;
$55: begin r_D:=r_L; clp5_r_PCp1; end;
$56: begin r_D:=do_read2(r_L,r_H); clp7_r_PCp1; end;
$57: begin r_D:=r_A; clp5_r_PCp1; end;
$58: begin r_E:=r_B; clp5_r_PCp1; end;
$59: begin r_E:=r_C; clp5_r_PCp1; end;
$5A: begin r_E:=r_D; clp5_r_PCp1; end;
$5C: begin r_E:=r_H; clp5_r_PCp1; end;
$5D: begin r_E:=r_L; clp5_r_PCp1; end;
$5E: begin r_E:=do_read2(r_L,r_H); clp7_r_PCp1; end;
$5F: begin r_E:=r_A; clp5_r_PCp1; end;
$60: begin r_H:=r_B; clp5_r_PCp1; end;
$61: begin r_H:=r_C; clp5_r_PCp1; end;
$62: begin r_H:=r_D; clp5_r_PCp1; end;
$63: begin r_H:=r_E; clp5_r_PCp1; end;
$65: begin r_H:=r_L; clp5_r_PCp1; end;
$66: begin r_H:=do_read2(r_L,r_H); clp7_r_PCp1; end;
$67: begin r_H:=r_A; clp5_r_PCp1; end;
$68: begin r_L:=r_B; clp5_r_PCp1; end;
$69: begin r_L:=r_C; clp5_r_PCp1; end;
$6A: begin r_L:=r_D; clp5_r_PCp1; end;
$6B: begin r_L:=r_E; clp5_r_PCp1; end;
$6C: begin r_L:=r_H; clp5_r_PCp1; end;
$6E: begin r_L:=do_read2(r_L,r_H); clp7_r_PCp1; end;
$6F: begin r_L:=r_A; clp5_r_PCp1; end;
$70: begin do_write2(r_L,r_H,r_B); clp7_r_PCp1; end;
$71: begin do_write2(r_L,r_H,r_C); clp7_r_PCp1; end;
$72: begin do_write2(r_L,r_H,r_D); clp7_r_PCp1; end;
$73: begin do_write2(r_L,r_H,r_E); clp7_r_PCp1; end;
$74: begin do_write2(r_L,r_H,r_H); clp7_r_PCp1; end;
$75: begin do_write2(r_L,r_H,r_L); clp7_r_PCp1; end;
$76: begin clp4_r_PCp1; end;
$77: begin do_write2(r_L,r_H,r_A); clp7_r_PCp1; end;
$78: begin r_A:=r_B; clp5_r_PCp1; end;
$79: begin r_A:=r_C; clp5_r_PCp1; end;
$7A: begin r_A:=r_D; clp5_r_PCp1; end;
$7B: begin r_A:=r_E; clp5_r_PCp1; end;
$7C: begin r_A:=r_H; clp5_r_PCp1; end;
$7D: begin r_A:=r_L; clp5_r_PCp1; end;
$7E: begin r_A:=do_read2(r_L,r_H); clp7_r_PCp1; end;
$80: begin tmp2:=r_A+r_B; RF2; if (((tmp2 xor r_A xor r_B) and $10)<>0) then
 begin rF8; end; if2;  r_A:=(tmp2 and $FF); clp4_r_PCp1; end;

$81: begin tmp2:=r_A+r_C; RF2;
 if (((tmp2 xor r_A xor r_C) and $10)<>0) then begin rF8; end;
 if2_rA1_clp4_r_PCp1; end;

$82: begin tmp2:=r_A+r_D; RF2; if (((tmp2 xor r_A xor r_D) and $10)<>0) then
 begin rF8; end; if2_rA1_clp4_r_PCp1; end;

$83: begin tmp2:=r_A+r_E; RF2; if (((tmp2 xor r_A xor r_E) and $10)<>0) then
 begin rF8; end; if2_rA1_clp4_r_PCp1; end;

$84: begin tmp2:=r_A+r_H; RF2; if (((tmp2 xor r_A xor r_H) and $10)<>0) then
 begin rF8; end; if2_rA1_clp4_r_PCp1; end;

$85: begin tmp2:=r_A+r_L; RF2; if (((tmp2 xor r_A xor r_L) and $10)<>0) then
 begin rF8; end; if2_rA1_clp4_r_PCp1; end;

$86: begin tmp1:=do_read2(r_L,r_H); tmp2:=r_A+tmp1; RF2;
 if (((tmp2 xor r_A xor tmp1) and $10)<>0) then begin rF8; end;
 if2; rA1; clp7_r_PCp1; end;

$87: begin tmp2:=r_A+r_A; RF2;
 if (((tmp2 xor r_A xor r_A) and $10)<>0) then begin rF8; end;
 if2_rA1_clp4_r_PCp1; end;

$88: begin tmp2:=r_A+r_B; if1;
 RF2; if (((tmp2 xor r_A xor r_B) and $10)<>0) then begin rF8; end;
 if2_rA1_clp4_r_PCp1; end;

$89: begin tmp2:=r_A+r_C; if1;
 RF2; if (((tmp2 xor r_A xor r_C) and $10)<>0) then begin rF8; end;
 if2_rA1_clp4_r_PCp1; end;

$8A: begin tmp2:=r_A+r_D; if1;
 RF2; if (((tmp2 xor r_A xor r_D) and $10)<>0) then begin rF8; end;
 if2_rA1_clp4_r_PCp1; end;

$8B: begin tmp2:=r_A+r_E; if1;
 RF2; if (((tmp2 xor r_A xor r_E) and $10)<>0) then begin rF8; end;
 if2_rA1_clp4_r_PCp1; end;

$8C: begin tmp2:=r_A+r_H; if1;
 RF2; if (((tmp2 xor r_A xor r_H) and $10)<>0) then begin rF8; end;
 if (tmp2>$FF) then begin r_F:=r_F or f_C; end; rA1; clp4_r_PCp1; end;

$8D: begin tmp2:=r_A+r_L; if1;
 RF2; if (((tmp2 xor r_A xor r_L) and $10)<>0) then begin rF8; end;
 if2_rA1_clp4_r_PCp1; end;

$8E: begin tmp1:=do_read2(r_L,r_H); tmp2:=r_A+tmp1; if1;
 RF2; if (((tmp2 xor r_A xor tmp1) and $10)<>0) then begin rF8; end;
 if2; rA1; clp7_r_PCp1; end;

$8F: begin tmp2:=r_A+r_A; if1;
 RF2; if (((tmp2 xor r_A xor r_A) and $10)<>0) then
 begin rF8; end; if2_rA1_clp4_r_PCp1; end;

$90: begin tmp2:=(r_A-r_B) and $FF; RF3; if (r_A<r_B) then begin rF7; end;
 if (((tmp2 xor r_A xor r_B) and $10)<>0) then begin rF8; end; rA2_clp4_r_PCp1; end;

$91: begin tmp2:=(r_A-r_C) and $FF; RF3; if (r_A<r_C) then begin rF7; end;
 if (((tmp2 xor r_A xor r_C) and $10)<>0) then begin rF8; end; rA2_clp4_r_PCp1; end;

$92: begin tmp2:=(r_A-r_D) and $FF; RF3;
 if (r_A<r_D) then begin rF7; end; if (((tmp2 xor r_A xor r_D) and $10)<>0) then
 begin rF8; end; rA2_clp4_r_PCp1; end;

$93: begin tmp2:=(r_A-r_E) and $FF; RF3; if (r_A<r_E) then begin rF7; end;
  if (((tmp2 xor r_A xor r_E) and $10)<>0) then begin rF8; end;
 rA2_clp4_r_PCp1; end;

$94: begin tmp2:=(r_A-r_H) and $FF; RF3; if (r_A<r_H) then
 begin rF7; end; if (((tmp2 xor r_A xor r_H) and $10)<>0) then
 begin rF8; end; rA2_clp4_r_PCp1; end;

$95: begin tmp2:=(r_A-r_L) and $FF; RF3; if (r_A<r_L) then
begin r_F:=r_F or f_C; end; if (((tmp2 xor r_A xor r_L) and $10)<>0) then
 begin rF8; end; rA2_clp4_r_PCp1; end;

$96: begin tmp1:=do_read2(r_L,r_H); tmp2:=(r_A-tmp1) and $FF; RF3;
 if (r_A<tmp1) then begin rF7; end;
 if (((tmp2 xor r_A xor tmp1) and $10)<>0) then begin rF8; end;
 rA2; clp7_r_PCp1; end;

$97: begin rF4; r_A:=0; clp4_r_PCp1; end;
$98: begin if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0; tmp2:=(r_A-r_B-tmp3) and $FF;
 RF3; if (r_A<r_B+tmp3) then begin rF7; end;
 if (((tmp2 xor r_A xor r_B) and $10)<>0) then begin rF8; end; rA2_clp4_r_PCp1; end;

$99: begin if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0; tmp2:=(r_A-r_C-tmp3) and $FF;
 RF3; if (r_A<(r_C+tmp3)) then begin rF7; end; if (((tmp2 xor r_A xor r_C) and $10)<>0) then
 begin rF8; end; rA2_clp4_r_PCp1; end;

$9A: begin if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0; tmp2:=(r_A-r_D-tmp3) and $FF;
 RF3; if (r_A<r_D+tmp3) then begin rF7; end; if (((tmp2 xor r_A xor r_D) and $10)<>0) then
 begin rF8; end; rA2_clp4_r_PCp1; end;

$9B: begin if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0; tmp2:=(r_A-r_E-tmp3) and $FF;
 RF3; if (r_A<r_E+tmp3) then begin rF7; end;
 if (((tmp2 xor r_A xor r_E) and $10)<>0) then begin rF8; end; rA2_clp4_r_PCp1; end;

$9C: begin if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0; tmp2:=(r_A-r_H-tmp3) and $FF;
 RF3; if (r_A<r_H+tmp3) then begin rF7; end; if (((tmp2 xor r_A xor r_H) and $10)<>0) then
 begin rF8; end; rA2_clp4_r_PCp1; end;

$9D: begin if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0; tmp2:=(r_A-r_L-tmp3) and $FF;
 RF3; if (r_A<r_L+tmp3) then begin rF7; end; if (((tmp2 xor r_A xor r_L) and $10)<>0) then
 begin rF8; end; rA2_clp4_r_PCp1; end;

$9E: begin tmp1:=do_read2(r_L,r_H); if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
 tmp2:=(r_A-tmp1-tmp3) and $FF; RF3; if (r_A<tmp1+tmp3) then begin rF7; end;
 if (((tmp2 xor r_A xor tmp1) and $10)<>0) then begin rF8; end; rA2; clp7_r_PCp1; end;

$9F: begin if ((r_F and f_C)<>0) then tmp2:=$FF else tmp2:=0; RF3; if (tmp2<>0) then
 begin r_F:=r_F or (f_A or f_C); end; rA2_clp4_r_PCp1; end;

$A0: begin r_A:=r_A and r_B;rF5_clp4_r_PCp1; end;
$A1: begin r_A:=r_A and r_C; rF5_clp4_r_PCp1; end;
$A2: begin r_A:=r_A and r_D; rF5_clp4_r_PCp1; end;
$A3: begin r_A:=r_A and r_E; rF5_clp4_r_PCp1; end;
$A4: begin r_A:=r_A and r_H; rF5_clp4_r_PCp1; end;
$A5: begin r_A:=r_A and r_L; rF5_clp4_r_PCp1; end;
$A6: begin tmp1:=do_read2(r_L,r_H); r_A:=r_A and tmp1; RF5; clp7_r_PCp1; end;
$A7: begin r_A:=r_A and r_A; rF5_clp4_r_PCp1; end;
$A8: begin r_A:=r_A xor r_B; rF5_clp4_r_PCp1; end;
$A9: begin r_A:=r_A xor r_C; rF5_clp4_r_PCp1; end;
$AA: begin r_A:=r_A xor r_D; rF5_clp4_r_PCp1; end;
$AB: begin r_A:=r_A xor r_E; rF5_clp4_r_PCp1; end;
$AC: begin r_A:=r_A xor r_H; rF5_clp4_r_PCp1; end;
$AD: begin r_A:=r_A xor r_L; rF5_clp4_r_PCp1; end;
$AE: begin tmp1:=do_read2(r_L,r_H); r_A:=r_A xor tmp1; RF5; clp7;
r_PCp1; end; $AF: begin r_A:=0; rF5_clp4_r_PCp1; end;

$B0: begin r_A:=r_A or r_B; rF5_clp4_r_PCp1; end;
$B1: begin r_A:=r_A or r_C; rF5_clp4_r_PCp1; end;
$B2: begin r_A:=r_A or r_D; rF5_clp4_r_PCp1; end;
$B3: begin r_A:=r_A or r_E; rF5_clp4_r_PCp1; end;
$B4: begin r_A:=r_A or r_H; rF5_clp4_r_PCp1; end;
$B5: begin r_A:=r_A or r_L; rF5_clp4_r_PCp1; end;
$B6: begin tmp1:=do_read2(r_L,r_H); r_A:=r_A or tmp1; RF5; clp7_r_PCp1; end;
$B7: begin r_A:=r_A or r_A; rF5_clp4_r_PCp1; end;
$B8: begin tmp2:=(r_A-r_B) and $FF; RF3; if (r_A<r_B) then begin rF7; end;
 if (((tmp2 xor r_A xor r_B) and $10)<>0) then begin rF8; end; clp4_r_PCp1; end;

$B9: begin tmp2:=(r_A-r_C) and $FF; RF3; if (r_A<r_C) then begin rF7; end;
 if (((tmp2 xor r_A xor r_C) and $10)<>0) then begin rF8; end; clp4_r_PCp1; end;

$BA: begin tmp2:=(r_A-r_D) and $FF; RF3; if (r_A<r_D) then begin rF7; end;
 if (((tmp2 xor r_A xor r_D) and $10)<>0) then begin rF8; end; clp4_r_PCp1; end;

$BB: begin tmp2:=(r_A-r_E) and $FF; RF3; if (r_A<r_E) then begin rF7; end;
 if (((tmp2 xor r_A xor r_E) and $10)<>0) then begin rF8; end;
 clp4_r_PCp1; end;

$BC: begin tmp2:=(r_A-r_H) and $FF; RF3; if (r_A<r_H) then begin rF7; end;
 if (((tmp2 xor r_A xor r_H) and $10)<>0) then begin rF8; end; clp4_r_PCp1; end;

$BD: begin tmp2:=(r_A-r_L) and $FF; RF3; if (r_A<r_L) then begin rF7; end;
 if (((tmp2 xor r_A xor r_L) and $10)<>0) then begin rF8; end; clp4_r_PCp1; end;

$BE: begin tmp1:=do_read2(r_L,r_H); tmp2:=(r_A-tmp1) and $FF; RF3;
 if (r_A<tmp1) then begin rF7; end; if (((tmp2 xor r_A xor tmp1) and $10)<>0) then
 begin rF8; end; clp7_r_PCp1; end; $BF: begin rf4; clp4_r_PCp1; end;

$C0: begin if ((r_F and f_Z)<>0) then begin clp5_r_PCp1; end else
 begin r_PC:=do_read(r_SP); r_PC:=r_PC+(do_read(r_SP+1) shl 8);
 r_SP:=(r_SP+2) and $FFFF; clp11; end; end;

$C1: begin r_C:=do_read(r_SP); r_B:=do_read(r_SP+1); r_SP:=(r_SP+2) and $FFFF;
 clp10_r_PCp1; end;

$C2: begin if ((r_F and f_Z)<>0) then begin clp10_r_PCp3; end
 else begin r_PC:=d_rdPCp1+((d_rdPCp2 shl 8)); clp10; end; end;

$C3: begin r_PC:=d_rdPCp1+((d_rdPCp2 shl 8)); clp10; end;
$C4: begin if ((r_F and f_Z)<>0) then begin clp11; r_PCp3; end else
 begin tmp1:=d_rdPCp1+((d_rdPCp2 shl 8)); r_SP:=(r_SP-2) and $FFFF;
 r_PCp3; do_write(r_SP,r_PC and $FF); do_write(r_SP+1,(r_PC shr 8) and $FF);
 r_PC:=tmp1; clp17; end; end;

$C5: begin r_SP:=(r_SP-2) and $FFFF; do_write(r_SP,r_C); do_write(r_SP+1,r_B);
  clp11; r_PCp1; end;

$C6: begin tmp1:=d_rdPCp1; tmp2:=r_A+tmp1; RF2;
 if (((tmp2 xor r_A xor tmp1) and $10)<>0) then begin rF6; end;
 if (tmp2>$FF) then begin r_F:=r_F or f_C; end; rA1; clp7_r_PCp2; end;

$C7: begin r_SP:=(r_SP-2) and $FFFF; inc(r_PC); do_write(r_SP,r_PC and $FF);
 do_write(r_SP+1,(r_PC shr 8) and $FF); r_PC:=0*8; clp11; end;

$C8: begin if ((r_F and f_Z)=0) then begin clp5_r_PCp1; end else
 begin r_PC:=do_read(r_SP); r_PC:=r_PC+(do_read(r_SP+1) shl 8);
 r_SP:=(r_SP+2) and $FFFF; clp11; end; end;

$C9: begin r_PC:=do_read(r_SP); r_PC:=r_PC+(do_read(r_SP+1) shl 8);
 r_SP:=(r_SP+2) and $FFFF; clp11; end;

$CA: begin if ((r_F and f_Z)=0) then begin clp10_r_PCp3; end
 else begin r_PC:=d_rdPCp1+(d_rdPCp2 shl 8); clp10; end; end;

$CB: begin begin r_PC:=d_rdPCp1+(d_rdPCp2 shl 8); clp10; end; end;
$CC: begin if ((r_F and f_Z)=0) then begin clp11; r_PCp3; end else
 begin tmp1:=d_rdPCp1+(d_rdPCp2 shl 8); r_SP:=(r_SP-2) and $FFFF;
 r_PCp3; do_write(r_SP,r_PC and $FF); do_write(r_SP+1,(r_PC shr 8) and $FF);
 r_PC:=tmp1; clp17; end end;

$CD: begin tmp1:=d_rdPCp1+(d_rdPCp2 shl 8);
 r_SP:=(r_SP-2) and $FFFF; r_PCp3; do_write(r_SP,r_PC and $FF);
 do_write(r_SP+1,(r_PC shr 8) and $FF); r_PC:=tmp1; clp17; end;

$CE: begin tmp1:=d_rdPCp1; tmp2:=r_A+tmp1; if1; RF2;
 if (((tmp2 xor r_A xor tmp1) and $10)<>0) then begin rF6; end;
 if (tmp2>$FF) then begin r_F:=r_F or f_C; end; rA1; clp7_r_PCp2; end;

$CF: begin r_SP:=(r_SP-2) and $FFFF; inc(r_PC); do_write(r_SP,r_PC and $FF);
 do_write(r_SP+1,(r_PC shr 8) and $FF); r_PC:=1*8; clp11; end;

$D0: begin if ((r_F and f_C)<>0) then begin clp5_r_PCp1; end else
 begin r_PC:=do_read(r_SP); r_PC:=r_PC+(do_read(r_SP+1) shl 8);
 r_SP:=(r_SP+2) and $FFFF; clp11; end end;

$D1: begin r_E:=do_read(r_SP); r_D:=do_read(r_SP+1); r_SP:=(r_SP+2) and $FFFF;
 clp10_r_PCp1; end;

$D2: begin if ((r_F and f_C)<>0) then begin clp10_r_PCp3; end
 else begin r_PC:=d_rdPCp1+(d_rdPCp2 shl 8); clp10; end; end;

$D3: begin do_output(d_rdPCp1,r_A); clp10; r_PCp2; end;

$D4: begin if ((r_F and f_C)<>0) then begin clp11; r_PCp3; end else
 begin tmp1:=d_rdPCp1+(d_rdPCp2 shl 8); r_SP:=(r_SP-2) and $FFFF;
 r_PCp3; do_write(r_SP,r_PC and $FF); do_write(r_SP+1,(r_PC shr 8) and $FF);
 r_PC:=tmp1; clp17; end; end;

$D5: begin r_SP:=(r_SP-2) and $FFFF; do_write(r_SP,r_E); do_write(r_SP+1,r_D);
 clp11; r_PCp1; end;

$D6: begin tmp1:=d_rdPCp1; tmp2:=(r_A-tmp1) and $FF; RF3;
 if (r_A<tmp1) then begin r_F:=r_F or f_C; end;
 if (((tmp2 xor r_A xor tmp1) and $10)<>0) then begin rF6; end; rA2; clp7_r_PCp2; end;

$D7: begin r_SP:=(r_SP-2) and $FFFF; inc(r_PC); do_write(r_SP,r_PC and $FF);
 do_write(r_SP+1,(r_PC shr 8) and $FF); r_PC:=2*8; clp11; end;

$D8: begin if ((r_F and f_C)=0) then begin clp5_r_PCp1; end else
 begin r_PC:=do_read(r_SP); r_PC:=r_PC+do_read(r_SP+1) shl 8; r_SP:=(r_SP+2) and $FFFF;
 clp11; end; end;

$D9: begin begin r_PC:=do_read(r_SP); r_PC:=r_PC+do_read(r_SP+1) shl 8;
 r_SP:=(r_SP+2) and $FFFF; clp11; end; end;

$DA: begin if ((r_F and f_C)=0) then begin clp10_r_PCp3; end else begin
 r_PC:=d_rdPCp1+(d_rdPCp2 shl 8); clp10; end; end;

$DB: begin r_A:=do_input(d_rdPCp1); clp10; r_PCp2; end;

$DC: begin if ((r_F and f_C)=0) then begin clp11; r_PCp3; end else
begin tmp1:=d_rdPCp1+(d_rdPCp2 shl 8); r_SP:=(r_SP-2) and $FFFF; r_PCp3;
do_write(r_SP,r_PC and $FF); do_write(r_SP+1,(r_PC shr 8) and $FF); r_PC:=tmp1; clp17;
 end; end;

$DD: begin begin tmp1:=d_rdPCp1+(d_rdPCp2 shl 8);
 r_SP:=(r_SP-2) and $FFFF; r_PCp3; do_write(r_SP,r_PC and $FF);
 do_write(r_SP+1,(r_PC shr 8) and $FF); r_PC:=tmp1; clp17; end; end;

$ED: begin begin tmp1:=d_rdPCp1+(d_rdPCp2 shl 8);
 r_SP:=(r_SP-2) and $FFFF; r_PCp3; do_write(r_SP,r_PC and $FF);
 do_write(r_SP+1,(r_PC shr 8) and $FF); r_PC:=tmp1; clp17; end; end;

$FD: begin begin tmp1:=d_rdPCp1+(d_rdPCp2 shl 8);
 r_SP:=(r_SP-2) and $FFFF; r_PCp3; do_write(r_SP,r_PC and $FF);
 do_write(r_SP+1,(r_PC shr 8) and $FF); r_PC:=tmp1; clp17; end; end;

$DE: begin tmp1:=d_rdPCp1; if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0;
 tmp2:=(r_A-tmp1-tmp3) and $FF; RF3; if (r_A<tmp1+tmp3) then begin
 r_F:=r_F or f_C; end; if (((tmp2 xor r_A xor tmp1) and $10)<>0) then
 begin rF6; end; rA2; clp7_r_PCp2; end;

$DF: begin r_SP:=(r_SP-2) and $FFFF; inc(r_PC); do_write(r_SP,r_PC and $FF);
 do_write(r_SP+1,(r_PC shr 8) and $FF); r_PC:=3*8; clp11; end;

$E0: begin if ((r_F and f_P)<>0) then begin clp5_r_PCp1; end else
 begin r_PC:=do_read(r_SP); r_PC:=r_PC+do_read(r_SP+1) shl 8;
 r_SP:=(r_SP+2) and $FFFF; clp11; end ; end;

$E1: begin r_L:=do_read(r_SP); r_H:=do_read(r_SP+1); r_SP:=(r_SP+2) and $FFFF;
 clp10_r_PCp1; end;

$E2: begin if ((r_F and f_P)<>0) then begin clp10_r_PCp3; end else
 begin r_PC:=d_rdPCp1+(d_rdPCp2 shl 8); clp10; end; end;

$E3: begin tmp1:=do_read(r_SP); do_write(r_SP,r_L); r_L:=tmp1;
 tmp1:=do_read(r_SP+1); do_write(r_SP+1,r_H); r_H:=tmp1; clock:=clock+18; r_PCp1; end;

$E4: begin if ((r_F and f_P)<>0) then begin clp11; r_PCp3; end else
 begin tmp1:=d_rdPCp1+(d_rdPCp2 shl 8); r_SP:=(r_SP-2) and $FFFF;
 r_PCp3; do_write(r_SP,r_PC and $FF); do_write(r_SP+1,(r_PC shr 8) and $FF);
 r_PC:=tmp1; clp17; end; end;

$E5: begin r_SP:=(r_SP-2) and $FFFF; do_write(r_SP,r_L); do_write(r_SP+1,r_H);
 clp11; r_PCp1; end;

$E6: begin r_A:=r_A and d_rdPCp1; RF5; clp7_r_PCp2; end;

$E7: begin r_SP:=(r_SP-2) and $FFFF; inc(r_PC); do_write(r_SP,r_PC and $FF);
 do_write(r_SP+1,(r_PC shr 8) and $FF); r_PC:=4*8; clp11; end;

$E8: begin if ((r_F and f_P)=0) then begin clp5_r_PCp1; end else
 begin r_PC:=do_read(r_SP); r_PC:=r_PC+do_read(r_SP+1) shl 8; r_SP:=(r_SP+2) and $FFFF;
 clp11; end; end;

$E9: begin r_PC:=(r_H shl 8)+r_L; clp5; end;

$EA: begin if ((r_F and f_P)=0) then begin clp10_r_PCp3; end else
 begin r_PC:=d_rdPCp1+(d_rdPCp2 shl 8); clp10; end; end;

$EB: begin tmp1:=r_D; r_D:=r_H; r_H:=tmp1; tmp1:=r_E; r_E:=r_L; r_L:=tmp1; clp4;
 r_PCp1; end;

 $EC: begin if ((r_F and f_P)=0) then begin clp11; r_PCp3; end else
 begin tmp1:=d_rdPCp1+(d_rdPCp2 shl 8); r_SP:=(r_SP-2) and $FFFF;
 r_PCp3; do_write(r_SP,r_PC and $FF); do_write(r_SP+1,(r_PC shr 8) and $FF);
 r_PC:=tmp1; clp17; end; end;

 $EE: begin r_A:= r_A xor d_rdPCp1; RF5; clp7_r_PCp2; end;
 $EF: begin r_SP:=(r_SP-2) and $FFFF; inc(r_PC); do_write(r_SP,r_PC and $FF);
 do_write(r_SP+1,(r_PC shr 8) and $FF); r_PC:=5*8; clp11; end;

 $F0: begin if ((r_F and f_S)<>0) then begin clp5_r_PCp1; end else
 begin r_PC:=do_read(r_SP); r_PC:=r_PC+(do_read(r_SP+1) shl 8);
 r_SP:=(r_SP+2) and $FFFF; clp11; end; end;

$F1: begin r_F:=do_read(r_SP); r_A:=do_read(r_SP+1); r_SP:=(r_SP+2) and $FFFF;
 clp10_r_PCp1; end;

$F2: begin if ((r_F and f_S)<>0) then begin clp10_r_PCp3; end else
 begin r_PC:=d_rdPCp1+(d_rdPCp2 shl 8); clp10; end; end;

$F4: begin if ((r_F and f_S)<>0) then begin clp11; r_PCp3; end else
 begin tmp1:=d_rdPCp1+(d_rdPCp2 shl 8); r_SP:=(r_SP-2) and $FFFF;
 r_PCp3; do_write(r_SP,r_PC and $FF); do_write(r_SP+1,(r_PC shr 8) and $FF);
 r_PC:=tmp1; clp17; end; end;

$F5: begin r_SP:=(r_SP-2) and $FFFF; do_write(r_SP,r_F); do_write(r_SP+1,r_A);
 clp11; r_PCp1; end;

$F6: begin r_A:=r_A or d_rdPCp1; RF5; clp7_r_PCp2; end;

$F7: begin r_SP:=(r_SP-2) and $FFFF; inc(r_PC); do_write(r_SP,r_PC and $FF);
 do_write(r_SP+1,(r_PC shr 8) and $FF); r_PC:=6*8; clp11; end;

$F8: begin if ((r_F and f_S)=0) then begin clp5_r_PCp1; end else
 begin r_PC:=do_read(r_SP); r_PC:=r_PC+(do_read(r_SP+1) shl 8);
 r_SP:=(r_SP+2) and $FFFF; clp11; end; end;

$F9: begin r_SP:=(r_H shl 8)+r_L; clp5_r_PCp1; end;
$FA: begin if ((r_F and f_S)=0) then begin clp10_r_PCp3; end else
 begin r_PC:=d_rdPCp1+(d_rdPCp2 shl 8); clp10; end; end;

$FC: begin if ((r_F and f_S)=0) then begin clp11; r_PCp3; end else
 begin tmp1:=d_rdPCp1+(d_rdPCp2 shl 8); r_SP:=(r_SP-2) and $FFFF;
 r_PCp3; do_write(r_SP,r_PC and $FF); do_write(r_SP+1,(r_PC shr 8) and $FF);
 r_PC:=tmp1; clp17; end; end;

$FE: begin tmp1:=d_rdPCp1; tmp2:=(r_A-tmp1) and $FF; RF3;
  if (r_A<tmp1) then begin r_F:=r_F or f_C; end;
 if (((tmp2 xor r_A xor tmp1) and $10)<>0) then begin rF6; end; clp7;
 r_PCp2; end;

$FF: begin r_SP:=(r_SP-2) and $FFFF; inc(r_PC); do_write(r_SP,r_PC and $FF);
 do_write(r_SP+1,(r_PC shr 8) and $FF); r_PC:=7*8; clp11; end end;
end;

rgA:=Cardinal(r_A);rgB:=Cardinal(r_b);rgC:=Cardinal(r_c);rgD:=Cardinal(r_d);
rgE:=Cardinal(r_e);rgH:=Cardinal(r_H);rgL:=Cardinal(r_L);rgF:=Cardinal(r_F);
rgPC:=Cardinal(r_PC);rgSP:=Cardinal(r_SP);

fS:=Cardinal(f_S);fZ:=Cardinal(f_Z);f5:=Cardinal(f_5);fA:=Cardinal(f_A);
f3:=Cardinal(f_3);fP:=Cardinal(f_P);f1:=Cardinal(f_1);fC:=Cardinal(f_C);
{$R+}
end;



procedure TMainForm.draw_screen1;

Begin
 {$R-}
//if FullScreen1.Checked then      // на весь экран или нет
MainForm.Canvas.StretchDraw(rect(0,0,MainForm.Width-0,MainForm.Height-30), gamecanvas)
//else
//MainForm.Canvas.Draw(0,0,gamecanvas);
 {$R+}
end;



//function col_index(port : Cardinal; color : Cardinal): Cardinal; // колор в зависимоти от порта С

var col_index_port,col_index_color,col_index_result:cardinal;
procedure TMainForm.col_index;
Var port,color,result_:Cardinal;
begin
 {$R-}
port:=col_index_port; color:=col_index_color;
 Result_:=LVColBlack;
 if ((port and $40)<>0) then Result_:= (Result_ xor LVColBlue);
 if ((port and $20)<>0) then Result_:= (Result_ xor LVColLime);
 if ((port and $10)<>0) then Result_:= (Result_ xor LVColRed);
// case color of
 if color = LVColBlack then
  begin
  if ((port and $08)=0) then
  begin   Result_:= (Result_ xor LVColRed);   end;
  if ((port and $04)=0) then
  begin   Result_:= (Result_ xor LVColBlue);   end;
  end else
 if color = LVColLime then begin  Result_:= (Result_ xor LVColLime);  end else
 if color = LVColRed then begin  Result_:= (Result_ xor LVColRed);
   if ((port and $02)=0) then
   begin    Result_:= (Result_ xor LVColLime);   end;  end else
 if color = LVColBlue then begin Result_:= (Result_ xor LVColBlue);
  if ((port and $01)=0) then
   begin    Result_:= (Result_ xor LVColRed);   end;  end;

col_index_result:=result_;
 {$R+}
end;



var My_col_inp,My_col_result:Cardinal;

Procedure TMainForm.My_col2;
var inp,result:Cardinal;
begin
 {$R-}
inp:=My_col_inp;
if inp=0 then My_col_result:=LVColBlack else
if inp=1 then My_col_result:=LVColLime else
if inp=2 then My_col_result:=LVColBlue else
if inp=3 then My_col_result:=LVColRed else
 {$R+}
end;


var SupCol2_c1,SupCol2_b,SupCol2_x:Cardinal;

var SupCol2_Result:Cardinal;
Procedure TMainForm.SupCol2;
 Var c1,b,x,_Result:Cardinal;
 pix:Cardinal;
begin
 {$R-}
 c1:=SupCol2_c1; b:=SupCol2_b; x:=SupCol2_x; pix:=0;
 case x of
 1: begin
  if (b and 128)=128 then pix:=pix+1;
  if (b and 8)=8  then pix:=pix+2;
    end;
 2: begin
  if (b and 64)=64 then pix:=pix+1;
  if (b and 4)=4  then pix:=pix+2;
    end;
 3: begin
  if (b and 32)=32 then pix:=pix+1;
  if (b and 2)=2 then pix:=pix+2;
   end;
 4: begin
  if (b and 16)=16 then pix:=pix+1;
  if (b and 1)=1  then pix:=pix+2;
   end;
 end;
  col_index_port:=c1;
  My_Col_inp:=pix;My_Col2;
  col_index_color:=My_col_result;
  col_index;SupCol2_Result:=col_index_result;
  {$R+}
end;

var draw_screen2_i:Cardinal;

procedure TMainForm.draw_screen2; //Рисуем с video на экран (Форму)

var vertX,gorY : Cardinal;

begin

   vertX:= (draw_screen2_i mod 64)*4; gorY:=(draw_screen2_i div 64)*1;

   Rports_a:=$C1;Rports;

   SupCol2_c1:=Rports_result;Rvideo_a:=draw_screen2_i;Rvideo;

   SupCol2_b:=Rvideo_result;

   SupCol2_x:=1;SupCol2;
   gamecanvas.Canvas.Pixels[vertX,gorY]:= SupCol2_Result;
   SupCol2_x:=2;SupCol2;
   gamecanvas.Canvas.Pixels[vertX+1,gorY]:=SupCol2_Result;
   SupCol2_x:=3;SupCol2;
   gamecanvas.Canvas.Pixels[vertX+2,gorY]:=SupCol2_Result;
   SupCol2_x:=4;SupCol2;
   gamecanvas.Canvas.Pixels[vertX+3,gorY]:=SupCol2_Result;
end;

procedure TMainForm.draw_screen; //Рисуем с video на экран (Форму)

var i:Cardinal;

begin
{$R-}

for i:=0 to $3fff do begin

  Rvideo_a:=i;Rvideo;
  RVideoDirty_a:=i;RVideoDirty;
 if Rvideo_Result<>RVideoDirty_Result then //сравниваем значения , а есть ли изменения
  begin
  draw_screen2_i:=i; draw_screen2;
  Rvideo_a:=i;Rvideo;
  WVideoDirty_a:=i; WVideoDirty_b:=Rvideo_Result;WVideoDirty;
  end;
 end;
draw_screen1;
{$R+}
end;




procedure TMainForm.FirstPusk; //первый запуск
 begin
 // создадим канву для рисования
 gamecanvas:=tbitmap.Create;
 gamecanvas.Width:=256;
 gamecanvas.Height:=256;

 ResetComp; // первоночальный сброс всего
 TimerMain.Enabled:=true; // запускаем основной таймер
end;

function TMainForm.readmask (keynum: word): word; // маска клавы
begin
result:= $72FF;
case keynum of
  8: begin result:= $23FF end; // BCK
  13: begin result:= $13FF end; // ENTER
	 16: begin result:= $70FF end; // SHIFT
  32: begin result:= $30FF end; // SPC

  37: begin result:= $FF32 end; // <-
  38: begin result:= $FF31 end; // UP
  39: begin result:= $FF30 end; // ->
  40: begin result:= $FF33 end; // DOWN

  48: begin result:= $06FF end; // 0
	 49: begin result:= $47FF end; // 1
	 50: begin result:= $46FF end; // 2
 	 51: begin result:= $45FF end; // 3
 	 52: begin result:= $44FF end; // 4
 	 53: begin result:= $43FF end; // 5
 	 54: begin result:= $00FF end; // 6
 	 55: begin result:= $01FF end; // 7
 	 56: begin result:= $02FF end; // 8
 	 57: begin result:= $07FF end; // 9

 	 65: begin result:= $64FF end; // A
  66: begin result:= $31FF end; // B
  67: begin result:= $57FF end; // C
  68: begin result:= $27FF end; // D
  69: begin result:= $54FF end; // E
  70: begin result:= $67FF end; // F
  71: begin result:= $10FF end; // G
 	 72: begin result:= $16FF end; // H
 	 73: begin result:= $75FF end; // I
 	 74: begin result:= $52FF end; // J
  75: begin result:= $55FF end; // K
 	 76: begin result:= $22FF end; // L
 	 77: begin result:= $76FF end; // M
 	 78: begin result:= $53FF end; // N
 	 79: begin result:= $21FF end; // O
 	 80: begin result:= $63FF end; // P
 	 81: begin result:= $71FF end; // Q
  82: begin result:= $20FF end; // R
 	 83: begin result:= $77FF end; // S
 	 84: begin result:= $74FF end; // T
  85: begin result:= $56FF end; // U
 	 86: begin result:= $26FF end; // V
 	 87: begin result:= $65FF end; // W
 	 88: begin result:= $73FF end; // X
 	 89: begin result:= $66FF end; // Y
 	 90: begin result:= $17FF end; // Z

 	 107: begin result:= $05FF end; // =/+ -> =/-
 	 109: begin result:= $05FF end; // -/_ -> =/-

 	 114: begin result:= $FF23 end; // F3
 	 115: begin result:= $FF22 end; // F4
 	 116: begin result:= $FF21 end; // F5

 	 36: begin result:= $FF20 end; // Home

 	 219: begin result:= $11FF end; // [
 	 221: begin result:= $12FF end; // ]
 	 190: begin result:= $24FF end; // .
 	 188: begin result:= $37FF end; // ,
 	 192: begin result:= $72FF end; //
end;

end;

procedure TMainForm.FormActivate(Sender: TObject);
begin
if FPusk then // а это первый ли запуск
 begin
 FPusk:=false;
 FirstPusk;
 end;
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
DragAcceptFiles(MainForm.Handle, true); // сделаем драг анд дроб :)
FPusk:=true; // запомним первый запуск
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin
DragAcceptFiles(Handle, False);

end;

procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word; //опрос клавы
 Shift: TShiftState);
begin
 kbd(readmask(key),true); // нажали
// i8080_do_opcodes(opcodes_to_run);
end;

procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
 kbd(readmask(key),false); // отпустии
end;

procedure TMainForm.TimerMainTimer(Sender: TObject); // основной таймер
var j,a: word;i: integer;s: string;
begin
//if (pause) then begin exit; end; // если пауза курим бамбук :)
 i8080_do_opcodes(opcodes_to_run);
 draw_screen;
end;

procedure TMainForm.ResetComp;
begin
 rgB := 0; rgC := 0; rgD := 0; rgE := 0; rgH := 0; rgL := 0; rgA := 0; rgF := 0;
 rgPC := 0; rgSP := 0;

 pause := false;


 fS := (1 SHL 7);
 fZ :=( 1 SHL 6);
 f5 := (1 SHL 5);
 fA := (1 SHL 4);
 f3 := (1 SHL 3);
 fP := (1 SHL 2);
 f1 := (1 SHL 1);
 fC := (1 SHL 0);

 BasicStack := $AFC1;
 BasicHotEntry := $02FD;
 BasicProgBegin := $0243;
 BasicProgEnd := $0245;


fillcharVideoDirty;



// restClock := 0;
 init_memory();
 reset1();
 load_bios();
 i8080_do_opcodes(0);
end;

procedure TMainForm.ResetCPU1Click(Sender: TObject);
begin
ResetComp;
end;

end.

20

SOURCE_DELPHI\004\
EmulForKOS.dpr

Код:
program EmulForKOS;

uses
  Forms,
  Windows,
  uMain in 'uMain.pas' {MainForm},
  uLVComp in 'uLVComp.pas';

{$R *.res}

begin
  SetThreadLocale(1049);
  Application.Initialize;
  Application.Title := 'ПК ЛЬВОВ';
  Application.CreateForm(TMainForm, MainForm);
  Application.Run;
end.

21

SOURCE_DELPHI\004\
uLVComp.pas

Код:
unit uLVComp;
interface

var

memoryM: array [0..65535] of byte=(..................);
videoM: array [0..16383] of byte=(..................);
portsM: array [0..255] of byte=(..................);
flagsM: array [0..255] of byte=(..................);

rgA:Cardinal=254; rgB:Cardinal=254; rgC:Cardinal=64; rgD:Cardinal=1; 
rgE:Cardinal=63; rgH:Cardinal=0; rgL:Cardinal=0; rgF:Cardinal=130; 
rgSP:Cardinal=44991; rgPC:Cardinal=56999; 
fS:Cardinal=128; fZ:Cardinal=64; f5:Cardinal=32; fA:Cardinal=16; 
f3:Cardinal=8; fP:Cardinal=4; f1:Cardinal=2; fC:Cardinal=1; 
implementation
end.

22

SOURCE_DELPHI\004\
uMain.pas

Код:
unit uMain;
interface
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls, ExtCtrls, Menus,MMSystem,ShellAPI, ImgList, ComCtrls,
 ToolWin,uLVcomp;
type
 TMainForm = class(TForm)
 TimerMain: TTimer; MainMenu1: TMainMenu;
 N1: TMenuItem; N2: TMenuItem; N3: TMenuItem; N4: TMenuItem;
 OpenDialogLvt: TOpenDialog;
 ResetCPU1: TMenuItem;
 N11: TMenuItem;
 procedure fillcharVideoDirty;
 procedure draw_screen1;
 procedure draw_screen2;
 Procedure SupCol2;
 Procedure My_col2;
 procedure col_index;
 procedure TimerMainTimer(Sender: TObject);
 procedure do_write(addr: Cardinal; bt: Cardinal);
 procedure i8080_init;
 function do_read(addr: Cardinal): Cardinal;
 procedure do_write2(a_lo: Cardinal; a_hi: Cardinal; bt: Cardinal);
 function do_read2(a_lo : Cardinal; a_hi : Cardinal): Cardinal;
 function do_input(port : Cardinal): Cardinal;
 procedure do_output(port : Cardinal; bt : Cardinal);
 procedure kbd(mask : word; press : boolean);
 procedure reset1;
 procedure load_bios;
 procedure do_pause();
 procedure i8080_do_opcodes(nb_cycles : Cardinal); //выполнение комманд процессора
 procedure draw_screen();
 procedure FirstPusk;
 function readmask (keynum: word): word;
 procedure N4Click(Sender: TObject);
 procedure N2Click(Sender: TObject);
 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
 procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
 procedure FormActivate(Sender: TObject);
 procedure NewLoadFile(filenameDnD: string;start : boolean);
 procedure ResetComp;
 procedure ResetCPU1Click(Sender: TObject);
 procedure FormCreate(Sender: TObject);
 procedure FormDestroy(Sender: TObject);
 procedure Wmemory; procedure Rmemory;
 procedure Wflags;  procedure Rflags;
 procedure Wvideo;  procedure Rvideo;
 procedure WVideoDirty; procedure RVideoDirty;
 procedure Wports; procedure Rports;
 procedure Wkbd_base; procedure Rkbd_base;
 procedure Wkbd_ext; procedure Rkbd_ext;
 private
 { Private declarations }
 public
 procedure WMDropFiles(var Msg: TMessage); message wm_DropFiles;
 { Public declarations }
 end;

var
 MainForm: TMainForm;

  VideoDirtyM : array [0..16384] of word; //буфер для быстрой прорисовки


 kbd_baseM : array [0..8] of byte; // массивы опроса клавиатуры
 kbd_extM : array [0..4] of byte;//=(1,2,3,4,5);

 FPusk: boolean; // первый запуск
 gamecanvas: tbitmap; // сюда все рисуем перед выводом на форму

 bios : array [0..65535] of byte; // массив для загрузки биоса, можно сразу грузить но вдруг пригодися
 Myfile: array [0..90000] of byte; //файл может быть большим DUMP SAV который

 pause : boolean; //пауза в эмуляторе
// opcodes_to_run:Cardinal = round ((1411200*2)/50{FPS});
// FPS:Cardinal=50; opcodes_to_run:Cardinal = 68500;
 FPS:Cardinal=1000; opcodes_to_run:Cardinal = 68500;
 myfilelength: Cardinal; // длина скачаного файла

 BasicStack,BasicHotEntry,BasicProgBegin,BasicProgEnd : Cardinal;

var LVColBlack:Cardinal=0; LVColLime:Cardinal=$00FF00; LVColBlue:Cardinal=$FF0000; LVColRed:Cardinal=$0000FF;
implementation
{$R *.dfm}
var Wmemory_a,Wmemory_b:Cardinal; procedure TMainForm.Wmemory; begin memoryM[Wmemory_a]:=Wmemory_b; end;
var Rmemory_a,Rmemory_result:Cardinal; procedure TMainForm.Rmemory; begin Rmemory_result:=memoryM[Rmemory_a];end;
var Wflags_a,Wflags_b:Cardinal; procedure TMainForm.Wflags; begin flagsM[Wflags_a]:=Wflags_b; end;
var Rflags_a,Rflags_result:Cardinal; procedure TMainForm.Rflags; begin Rflags_result:=flagsM[Rflags_a];end;
var Wvideo_a,Wvideo_b:Cardinal; procedure TMainForm.Wvideo; begin videoM[Wvideo_a]:=Wvideo_b; end;
var Rvideo_a,Rvideo_result:Cardinal; procedure TMainForm.Rvideo; begin Rvideo_result:=videoM[Rvideo_a];end;
var WVideoDirty_a,WVideoDirty_b:Cardinal; procedure TMainForm.WVideoDirty; begin VideoDirtyM[WVideoDirty_a]:=WVideoDirty_b; end;
var RVideoDirty_a,RVideoDirty_result:Cardinal; procedure TMainForm.RVideoDirty; begin RVideoDirty_result:=VideoDirtyM[RVideoDirty_a];end;
var Wports_a,Wports_b:Cardinal; procedure TMainForm.Wports; begin portsM[Wports_a]:=Wports_b; end;
var Rports_a,Rports_result:Cardinal; procedure TMainForm.Rports; begin Rports_result:=portsM[Rports_a];end;
var Wkbd_base_a,Wkbd_base_b:Cardinal; procedure TMainForm.Wkbd_base; begin kbd_baseM[Wkbd_base_a]:=Wkbd_base_b; end;
var Rkbd_base_a,Rkbd_base_result:Cardinal; procedure TMainForm.Rkbd_base; begin Rkbd_base_result:=kbd_baseM[Rkbd_base_a];end;
var Wkbd_ext_a,Wkbd_ext_b:Cardinal; procedure TMainForm.Wkbd_ext; begin kbd_extM[Wkbd_ext_a]:=Wkbd_ext_b; end;
var Rkbd_ext_a,Rkbd_ext_result:Cardinal; procedure TMainForm.Rkbd_ext; begin Rkbd_ext_result:=kbd_extM[Rkbd_ext_a];end;

procedure TMainForm.fillcharVideoDirty;
var c:Cardinal; begin {$R-} For c:=0 to 16384 do begin
Rvideo_a:=c; Rvideo; WVideoDirty_a:=c;WVideoDirty_b:=(Rvideo_result xor 1);WVideoDirty;{$R+} end; end;

procedure TMainForm.WMDropFiles(var Msg: TMessage); // порцедура отвечает за принятие перетаскиваемого файла
var FileName: array[0..256] of char;
begin DragQueryFile(THandle(Msg.WParam), 0, FileName, SizeOf(Filename));
MainForm.Caption:=FileName;NewLoadFile(FileName,true);DragFinish(THandle(Msg.WParam));end;

procedure TMainForm.do_write(addr : Cardinal; bt : Cardinal); // если нужно будем записывать :-)
begin
 {$R-}
if addr> $FFFF then addr:=$FFFF;
 if (addr>=$C000) then
 begin exit; end;
Rports_a:=$C2;Rports; if ((Rports_result and 2)<>0) then begin Wmemory_A:=addr; Wmemory_B:=bt; Wmemory; end else
if (addr<$4000) then begin exit; end else
if (addr<$8000) then begin Wvideo_a:=(addr-$4000);Wvideo_b:=bt; Wvideo; end else
begin Wmemory_A:=addr; Wmemory_B:=bt; Wmemory; end;
 {$R+}
end;


procedure TMainForm.i8080_init;

var j,i : Cardinal;
begin
 {$R-}
for i:=0 to 255 do
 begin
 {flags[i]:=f1 or fP;} Wflags_a:=i;Wflags_b:=(f1 or fP);Wflags;
for j:=0 to 7 do
 begin
  if ((i and (1 SHL j))<>0) then
    begin
  { flags[i]:=(flags[i] xor fP);}
   Rflags_a:=i;Rflags;
  Wflags_a:=i;Wflags_b:=(Rflags_Result xor fP);Wflags;
    end;
  end;
 if ((i and $80)<>0) then
 begin
   { flags[i]:=(flags[i] or fS);}
     Rflags_a:=i;Rflags;
   Wflags_a:=i;Wflags_b:=(Rflags_Result or fS);Wflags;
    end;
  if (i=0) then
    begin
    { flags[i]:=(flags[i] or fZ);}
     Rflags_a:=i;Rflags;
   Wflags_a:=i;Wflags_b:=(Rflags_Result or fZ);Wflags;
    end;
 end;
 {$R+}
end;




function TMainForm.do_read(addr : Cardinal): Cardinal; // считаем значение из пямяти
begin
 {$R-}
if addr> $FFFF then addr:=$FFFF;
RPorts_a:=$C2;RPorts; if ((RPorts_result and 2)<>0) then
 begin  Rmemory_A:=addr; Rmemory; result := Rmemory_result; end
 else if (addr>$7FFF) then begin  Rmemory_A:=addr; Rmemory; result := Rmemory_result; end
 else if (addr<$4000) then begin result := 0; end else
 begin Rvideo_a:=(addr-$4000); Rvideo; result := Rvideo_result; end;
 {$R+}
end;

procedure TMainForm.do_write2(a_lo: Cardinal; a_hi: Cardinal; bt: Cardinal);
begin {$R-} do_write(a_lo+(a_hi SHL 8),bt); {$R+}end;

function TMainForm.do_read2(a_lo : Cardinal; a_hi : Cardinal): Cardinal;
begin {$R-} result := do_read(a_lo+(a_hi SHL 8)); {$R+}end;


function TMainForm.do_input(port : Cardinal): Cardinal; // работа со значениями портов in
var i,r : Cardinal; nD2 ,nD0 : Cardinal;
begin
 {$R-}
 port:=$C0+(port and $13);
 case port of
 $C2:  begin Rports_a:=$C2;Rports; result := Rports_result; end;
 $D1:  begin Rports_a:=$D0;Rports; nD0:=not Rports_result; r:=0;
    For i:=0 to 7 do
    begin
    if ((nD0 and (1 SHL i))<>0) then begin rkbd_base_a:=i;rkbd_base; r:=(r or Rkbd_base_result); end;
    end;
    result := ((not r) and $FF);
   end;
 $D2: begin Rports_a:=$D2;Rports; nD2:= not Rports_result; r:=0;
   for i:=0 to 3 do begin if ((nD2 and (1 SHL i))<>0) then begin Rkbd_ext_a:=i;Rkbd_ext; r:=(r or Rkbd_ext_result);end;
    end;
    result := not ((r SHL 4) or (nD2 and $0F)) and $FF;
   end
  else begin result := $FF; end;
end;
 {$R+}
end;

procedure TMainForm.do_output(port : Cardinal; bt : Cardinal); // out
begin
 {$R-}
 port:=$C0+(port and $13);
 case port of
 $c1: begin // изменение порта цвета
   fillcharVideoDirty;
  end;

 end;
 Wports_a:=port;Wports_b:=bt; Wports;
  {$R+}
end ;

procedure TMainForm.kbd(mask : word; press : boolean); // по маске вкл выкл клавишу
var brow : byte; erow : byte; bcol : byte; ecol : byte;
begin
  {$R-}
 bcol:=(mask SHR 12) and $0F; brow:=(mask SHR 8) and $0F;
 ecol:=(mask SHR 4) and $0F; erow:=(mask SHR 0) and $0F;
 if ((brow<8) and (bcol<8)) then
 begin
 if (press) then begin Rkbd_base_a:=bcol;Rkbd_base;
  Wkbd_base_a:=bcol;Wkbd_base_b:=(Rkbd_base_result or (1 SHL brow));Wkbd_base; end
  else begin Rkbd_base_a:=bcol;Rkbd_base;
   Wkbd_base_a:=bcol;Wkbd_base_b:=(Rkbd_base_result and (not(1 SHL brow))); Wkbd_base; end;
 end;
 if ((erow<8) and (ecol<4)) then begin Rkbd_ext_a:=ecol;Rkbd_ext;
 if (press) then begin  Wkbd_ext_a:=ecol;Wkbd_ext_b:= (Rkbd_ext_result or (1 SHL erow));Wkbd_ext;
 end else begin Rkbd_ext_a:=ecol;Rkbd_ext; Wkbd_ext_a:=ecol;Wkbd_ext_b:=(Rkbd_ext_result and (not(1 SHL erow)));Wkbd_ext; end;
 end;
  {$R+}
end;

procedure TMainForm.reset1; // полный ресет :)
var i : word; begin {$R-} for i:=0 to 255 do begin
 Wports_a:=i;Wports_b:=$FF; Wports; end; {$R+} end;

procedure TMainForm.load_bios; // загрузка биоса из файла
var i: Cardinal;b: Byte;f: file of byte;
begin
 {$R-}
 i:=0; AssignFile(F,ExtractFilePath(Application.ExeName)+'\bios.dat');
 Reset(F); while not eof(f) do begin read(F,b); bios[i]:=b; inc(i); end;
 closeFile(F); i:=0;
 for i:=0 to $3FFF do begin Wmemory_a:=($C000+i);Wmemory_b:=bios[22+i];Wmemory; end;
 {$R+}
end;

procedure TMainForm.N2Click(Sender: TObject);
begin
 OpenDialogLvt.InitialDir:=ExtractFilePath(Application.ExeName);
 if OpenDialogLvt.Execute then NewLoadFile(OpenDialogLvt.FileName,true);
end;

procedure TMainForm.N4Click(Sender: TObject);
begin gamecanvas.Free;close;end;

procedure TMainForm.NewLoadFile(filenameDnD: string; start : boolean); //процедура загрузки всех видов файлов
var f:file of byte; b:Byte; s: string; posBas, Xend ,Xbeg ,Xrun : word; i: integer;
begin
 {$R-}
 s:='';
 AssignFile(f,filenameDnD); // распознаем что за файл
  Reset(f);
 for I:= 0 to 8 do begin  read(f,b);   s:=s+chr(b);  end;
 if s='LVOV/2.0/' then // стандартный LVT файл
  begin   read(f,b);
   if b=$D0 then  { это бинарник}   begin
   seek(F,0); // вернемся к началу файла
   i:=0;
   while not eof(f) do
   begin read(F,b); Myfile[i]:=b; inc(i); end;
   myfilelength:=i;
   closeFile(F);  //закрываем файл
   Xbeg:=Myfile[16]+Myfile[17]*256;   Xend:=Myfile[18]+Myfile[19]*256;
   Xrun:=Myfile[20]+Myfile[21]*256;
   if (start) then begin {warm_start();} rgPC:=Xrun; end;
   i:=0;
   while (i<=Xend-Xbeg) do begin do_write(Xbeg+i,Myfile[i+22]); inc(i); end;
   end
    else
   begin  //это бeйсик (надеюсь больше ничего нет :-) )
   seek(F,0); // вернемся к началу файла
   i:=0;
   while not eof(f) do
    begin read(F,b); Myfile[i]:=b; inc(i); end;
   myfilelength:=i-1;   {warm_start();}
//   posBas:=get_var(BasicProgBegin);
   i:=0;  while (i<myfilelength-16) do
    begin do_write(posBas+i,Myfile[i+16]); inc(i); end;
    // направим RUN
    MainForm.SetFocus;
    i8080_do_opcodes(opcodes_to_run);
     end;
  end;
  if s='LVOV/DUMP' then // стандартный SAV файл дампа эмулятор Калашникова
   begin
   seek(F,0); // вернемся к началу файла
   i:=0; while not eof(f) do begin read(F,b); Myfile[i]:=b; inc(i);end;
   i:=0; closeFile(F);
   while (i<$10000) do
   begin{ memory[i]:=Myfile[17+i];} Wmemory_A:=i; Wmemory_B:=Myfile[17+i]; Wmemory;inc(i);end;
   i:=0;  while (i<$4000) do begin
   Wvideo_a:=i;Wvideo_b:=Myfile[17+$10000+i];Wvideo; inc(i); end;
   i:=0;  while (i<$100) do begin

   Wports_a:=i;Wports_b:=Myfile[17+$10000+$4000+i]; Wports;
   inc(i);

   end;
   rgB:=Myfile[17+$10000+$4000+$100];   rgH:=Myfile[17+$10000+$4000+$100+4];
   rgC:=Myfile[17+$10000+$4000+$100+1];   rgL:=Myfile[17+$10000+$4000+$100+5];
   rgD:=Myfile[17+$10000+$4000+$100+2];   rgA:=Myfile[17+$10000+$4000+$100+6];
   rgE:=Myfile[17+$10000+$4000+$100+3];   rgF:=Myfile[17+$10000+$4000+$100+7];
   rgSP:=Myfile[17+$10000+$4000+$100+9]*256+Myfile[17+$10000+$4000+$100+8];
   rgPC:=Myfile[17+$10000+$4000+$100+11]*256+Myfile[17+$10000+$4000+$100+10];
   fillcharVideoDirty;   draw_screen;
   end;
 {$R-}
end;

procedure TMainForm.do_pause();
begin
	pause := not pause;
end;


procedure TMainForm.i8080_do_opcodes(nb_cycles : Cardinal);  //выполнение комманд процессора
var tmp3, tmp2, tmp1, opcode : integer;
var { регистрики} r_A,r_B,r_C,r_D,r_E,r_H,r_L,r_F,r_PC,r_SP : integer;
clock:Cardinal;
{ флаги} f_S, f_Z, f_5, f_A, f_3,f_P,f_1,f_C : Integer;
procedure m01m;begin tmp2:=tmp2+1 end;
procedure m02m;begin r_PC:=r_PC+3; end;
procedure m04m;Begin r_A:=(tmp2 and $FF); end;
procedure m06m;Begin r_A:=tmp2; end;
procedure m07m;Begin Rflags_a:=tmp2;Rflags; r_F:=(Rflags_result or (r_F and f_C)); end;
procedure m08m;Begin Rflags_a:=(tmp2 and $FF);Rflags; r_F:=Rflags_result; end;
procedure m09m;begin Rflags_a:=(tmp2);Rflags; r_F:=Rflags_result; end;
procedure m10m;begin Rflags_a:=(0);Rflags; r_F:=Rflags_result; end;
procedure m11m;begin Rflags_a:=(r_A);Rflags; r_F:=(Rflags_result or (r_F and f_A)); end;
procedure m12m;begin r_F:=(r_F or f_A); end;
procedure m13m;begin r_F:=(r_F or f_C); end;
procedure m14m;begin r_PC:=r_PC+1; end;
procedure m15m;begin r_PC:=r_PC+2; end;
procedure m16m;begin clock:=clock+4; end;
procedure m17m;begin clock:=clock+7; end;
procedure m18m;begin clock:=clock+5; end;
procedure m19m;begin clock:=clock+10; end;
procedure m20m;begin clock:=clock+11; end;
procedure m21m;begin clock:=clock+13; end;
procedure m22m;begin clock:=clock+16; end;
procedure m23m;begin clock:=clock+17; end;
procedure m24m;begin if ((r_F and f_C)<>0) then m01m else tmp2:=tmp2+0;end;
procedure m25m;begin m18m; m14m;end;
procedure m26m;begin m11m; m16m; m14m;end;
procedure m27m;begin m16m; m14m; end;
Function m28m:Cardinal; begin Result:=do_read(r_PC+2) end;
Function m29m:Cardinal; begin Result:=do_read(r_PC+1); end;
Function m30m:Cardinal; begin Result:=do_read2(r_L,r_H); end;
procedure m03m;begin m19m; m02m; end;
procedure m31m;begin m17m; m14m; end;
procedure m32m;begin if (tmp2>$FF) then begin m13m; end; end;
procedure m33m;begin m17m; m15m; end;
procedure m34m;begin m19m; m14m; end;
procedure m05m;Begin m32m; m04m; m27m; end;
procedure m35m;Begin m06m; m27m; end;
procedure m36m(a:Integer);Begin if (((tmp2 xor r_A xor a) and $10)<>0) then begin m12m; end; end;
procedure m37m(a:Integer); begin if ((r_F and f_C)<>0) then tmp3:=1 else tmp3:=0; tmp2:=(r_A-a-tmp3) and $FF;end;
Function m38m:Cardinal; begin Result:=m30m; m31m; end;
Function m39m:Cardinal; begin Result:=m29m; m33m; end;
procedure m40m(a:Integer); begin tmp2:=(r_A-a) and $FF; m09m; if (r_A<a) then begin m13m; end; m36m(a); m35m; end;
procedure m41m(a:Integer); begin m37m(a); m09m; if (r_A<(a+tmp3)) then begin m13m; end;
m36m(a); m35m; end;
procedure m42m(a:Integer); begin if (((tmp2 xor a) and $10)<>0) then begin m12m; end; end;
procedure m43m(a:Integer); begin m07m; m42m(a); end;
procedure m44m(a:Integer); begin do_write2(r_L,r_H,a); end;
Function m46m:Cardinal; begin m46m:=m29m+(m28m shl 8); end;
procedure m45m; begin r_PC:=m46m; end;
procedure m47m; begin tmp1:=m29m; end;
procedure m48m; begin tmp1:=m46m; end;
procedure m49m; begin r_PC:=do_read(r_SP);end;
procedure m50m; begin r_SP:=(r_SP-2) and $FFFF;end;
procedure m51m; begin r_PC:=tmp1; m23m; end;
procedure m52m; begin m48m; m50m; m02m; end;
Function m53m:Boolean;Begin if ((r_F and f_S)<>0) then Result:=True else Result:=False; end;
Function m54m:Boolean;Begin if ((r_F and f_S)=0) then Result:=True else Result:=False; end;
Function m55m:Cardinal; begin m55m:=(r_PC shr 8) and $FF; end;
procedure m56m; begin do_write(r_SP,r_PC and $FF); end;
Function m57m:Boolean;Begin if ((r_F and f_C)<>0) then Result:=True else Result:=False; end;
Function m58m:Boolean;Begin if ((r_F and f_P)=0) then Result:=True else Result:=False; end;
Function m59m:Boolean;Begin if ((r_F and f_C)=0) then Result:=True else Result:=False; end;
Function m60m:Boolean;Begin if ((r_F and f_Z)=0) then Result:=True else Result:=False; end;
procedure m61m(a:Integer); begin r_A:=r_A and a; end;
procedure m62m(a:Integer); begin if (r_A<a) then begin m13m; end; m36m(a); m27m; end;
procedure m63m(a:Integer); begin tmp2:=(r_A-a) and $FF; m09m; m62m(a);end;
procedure m64m(a:Integer); begin r_A:=(r_A or a);end;
procedure m65m; begin r_F:=r_F or f_C; end;
procedure m66m; begin r_SP:=(r_SP+2) and $FFFF;end;
procedure m67m(a:Integer); begin r_A:=(r_A xor a);end;
procedure m68m; begin m52m; m56m; do_write(r_SP+1,m55m); m51m; end;
procedure m69m; begin r_F:=(r_F and (not f_C)); end;
procedure m70m(a:Integer); begin tmp2:=r_A+a; m08m; m36m(a); m05m; end;
procedure m73m(a:Integer); begin tmp2:=r_A+a; m24m; m08m; m36m(a);end;
procedure m71m(a:Integer); begin m73m(a); m05m; end;
procedure m74m; begin tmp1:=m30m; end;
procedure m75m; begin tmp2:=(r_A-tmp1) and $FF; end;
procedure m76m; begin if (r_A<tmp1) then begin m65m; end; end;
procedure m77m; begin m45m; m19m; end;
procedure m78m; begin m20m; m02m; end;
Function m79m:Boolean;Begin if ((r_F and f_P)<>0) then Result:=True else Result:=False; end;
procedure m80m; begin r_PC:=r_PC+do_read(r_SP+1) shl 8; end;
//procedure m80m; begin r_PC:=r_PC+do_read(r_SP+1) shl 8; end;
procedure m82m; begin m49m; m80m; m66m; m20m; end;
//procedure m82m; begin m49m; m80m; m66m; m20m; end;
procedure m84m(a:Integer); begin r_B:=a; m25m; end;
procedure m85m(a:Integer); begin tmp2:=(a and $FF); end;



begin
 {$R-}
r_A:=integer(rgA);r_b:=integer(rgB);r_c:=integer(rgC);r_d:=integer(rgD);
r_e:=integer(rgE);r_H:=integer(rgH);r_L:=integer(rgL);r_F:=integer(rgF);
r_PC:=integer(rgPC);r_SP:=integer(rgSP);

f_S:=integer(fS);f_Z:=integer(fZ);f_5:=integer(f5);f_A:=integer(fA);
f_3:=integer(f3);f_P:=integer(fP);f_1:=integer(f1);f_C:=integer(fC);

 clock:=0; tmp1:=0; tmp2:=0; tmp3:=0; //бнулим :-)
 while (clock < nb_cycles) do
 begin
 opcode:=do_read(r_PC);

case opcode of // анализируем текущий код 00 .. FF, меняем значение clock в зависимоти от "длинны" команды ...
 // прыгаем по памяти, меняем значения регистров и портов ПРОЦ РАБОТАЕТ !!!!
$00: begin m27m; end;
$F3: begin m27m; end;
$FB: begin m27m; end;
$01: begin r_B:=m28m; r_C:=m29m; m03m; end;
$02: begin do_write2(r_C,r_B,r_A); m31m; end;
$03: begin r_C:=r_C+1; if (r_C>$FF) then begin r_C:=0; r_B:=r_B+1;
 if (r_B>$FF) then begin r_B:=0; end; end; m25m; end;

$04: begin m85m(r_B+1); m43m(r_B); r_B:=tmp2; m25m; end;
$05: begin m85m(r_B-1); m43m(r_B); r_B:=tmp2; m25m; end;
$06: begin r_B:=m39m; end;

$07: begin r_A:=r_A SHL 1; if (r_A>$FF) then begin r_A:=r_A or 1; m65m; r_A:= r_A and $FF; end
 else begin m69m; end; m27m; end;

$08:m27m; $10: m27m; $18:m27m; $20:m27m; $28:m27m; $30:m27m;$38:m27m;

$09: begin r_L:=r_L+r_C; r_H:=r_H+r_B; if (r_L>$FF) then
 begin inc(r_H); r_L:=(r_L and $FF); end;
 if (r_H>$FF) then begin r_H:=(r_H and $FF); m13m;
 end else begin m69m; end; m34m; end;

$0A: begin r_A:=do_read2(r_C,r_B); m31m; end;

$0B: begin r_C:=r_C-1; if (r_C<0) then begin r_C:=$FF; r_B:=r_B-1;
 if (r_B<0) then begin r_B:=$FF; end; end; m25m; end;

$0C: begin m85m(r_C+1); m43m(r_C); r_C:=tmp2; m25m; end;
$0D: begin m85m(r_C-1); m43m(r_C); r_C:=tmp2; m25m; end;
$0E: begin r_C:=m39m; end;

$0F: begin tmp1:=(r_A and 1); r_A:=(r_A shr 1); if (tmp1<>0) then
 begin r_A:=(r_A or $80); m13m; end else
 begin r_F:=(r_F and ( not f_C)); end; m27m; end;

$11: begin r_D:=m28m; r_E:=m29m; m03m; end;
$12: begin do_write2(r_E,r_D,r_A); m31m; end;

$13: begin r_E:=r_E+1; if (r_E>$FF) then begin r_E:=0; r_D:=r_D+1;
 if (r_D>$FF) then begin r_D:=0; end; end; m25m; end;

$14: begin m85m(r_D+1); m43m(r_D); r_D:=tmp2; m25m; end;
$15: begin m85m(r_D-1); m43m(r_D); r_D:=tmp2; m25m; end;

$16: begin r_D:=m39m; end;

$17: begin r_A:=(r_A shl 1); if m57m then
 begin r_A:=(r_A or 1); end; if (r_A>$FF) then begin m13m;
 r_A:=(r_A and $FF); end else begin m69m; end; m27m; end;

$19: begin r_L:=(r_L + r_E); r_H:=(r_H + r_D); if (r_L>$FF) then
 begin inc(r_H); r_L:=(r_L and $FF); end;
 if (r_H>$FF) then begin r_H:=(r_H and $FF); m13m;
 end else begin r_F:=(r_F and not (f_C)); end; m34m; end;

$1A: begin r_A:=do_read2(r_E,r_D); m31m; end;

$1B: begin r_E:=r_E-1; if (r_E<0) then begin r_E:=$FF; r_D:=r_D-1;
 if (r_D<0) then begin r_D:=$FF; end; end; m25m; end;

$1C: begin m85m(r_E+1); m43m(r_E); r_E:=tmp2; m25m; end;
$1D: begin m85m(r_E-1); m43m(r_E); r_E:=tmp2; m25m; end;
$1E: begin r_E:=m39m; end;

$1F: begin tmp1:=(r_A and 1); r_A:=(r_A SHR 1); if m57m then
 begin r_A:=(r_A or $80); end; if (tmp1<>0) then begin m13m; end
 else begin r_F:=(r_F and not(f_C)); end; m27m; end;

$21: begin r_H:=m28m; r_L:=m29m; m03m; end;

$22: begin m48m; do_write(tmp1,r_L); do_write(tmp1+1,r_H); m22m; m02m; end;

$23: begin r_L:=r_L+1; if (r_L>$FF) then begin r_L:=0; r_H:=r_H+1;
 if (r_H>$FF) then begin r_H:=0; end; end; m25m; end;

$24: begin m85m(r_H+1); m43m(r_H); r_H:=tmp2; m25m; end;
$25: begin m85m(r_H-1); m43m(r_H); r_H:=tmp2; m25m; end;

$26: begin r_H:=m39m; end;

$27: begin tmp1:=0; if (((r_F and f_C)<>0) or (r_A>$99)) then
 begin tmp1:=(tmp1 or $60); end;
 if (((r_F and f_A)<>0) or ((r_A and $0F)>$09)) then begin tmp1:=(tmp1 or $06); end;
 tmp2:=r_A+tmp1; m08m; m36m(tmp1); m32m; m04m; m27m; end;

$29: begin r_L:=r_L + r_L; r_H:=r_H + r_H; if (r_L>$FF) then begin
 inc(r_H); r_L:=(r_L and $FF); end; if (r_H>$FF) then begin
 r_H:=(r_H and $FF); m13m; end else begin m69m; end; m34m; end;

$2A: begin m48m; r_L:=do_read(tmp1); r_H:=do_read(tmp1+1); m22m; m02m; end;

$2B: begin r_L:=r_L-1; if (r_L <0) then begin r_L:=$FF; r_H:=r_H-1;
 if (r_H<0) then begin r_H:=$FF; end; end; m18m; m14m; end;

$2C: begin m85m(r_L+1); m43m(r_L); r_L:=tmp2; m25m; end;
$2D: begin m85m(r_L-1); m43m(r_L); r_L:=tmp2; m25m; end;
$2E: begin r_L:=m39m; end;
$2F: begin r_A:=(r_A xor $FF); m27m; end;
$31: begin r_SP:=(m28m shl 8)+m29m; m03m; end;
$32: begin do_write2(m29m,m28m,r_A); m21m; m02m; end;
$33: begin if (r_SP=$FFFF) then begin r_SP:=0; end else begin inc(r_SP); end; m25m; end;
$34: begin m74m; m85m(tmp1+1); m43m(tmp1); m44m(tmp2); m34m; end;
$35: begin m74m; m85m(tmp1-1); m43m(tmp1); m44m(tmp2); m34m; end;
$36: begin m44m(m29m); m19m; m15m; end;
$37: begin m13m; m27m; end;


$39: begin r_L:=(r_L + (r_SP and $FF)); r_H:=(r_H + ((r_SP shr 8) and $FF));
 if (r_L>$FF) then begin inc(r_H); r_L:=(r_L and $FF); end;
 if (r_H>$FF) then begin r_H:=(r_H and $FF); m13m; end else begin m69m; end; m34m; end;

$3A: begin r_A:=do_read2(m29m,m28m); m21m; m02m; end;

$3B: begin if (r_SP<>0) then begin r_SP:=r_SP-1; end else begin r_SP:=$FFFF; end;
 m25m; end;
$3C: begin m85m(r_A+1); m43m(r_A); m06m; m25m; end;
$3D: begin m85m(r_A-1); m43m(r_A); m06m; m25m; end;
$3E: begin r_A:=m39m; end;
$3F: begin r_F:=r_F xor f_C; m27m; end;

$40:m25m;$52:m25m; $5B:m25m; $64:m25m; $6D:m25m; $7F:m25m;
//procedure m84m(a:Integer); begin r_B:=a; m25m; end;
$41: m84m(r_C); $42: m84m(r_D); $43: m84m(r_E); $44: m84m(r_H); $45: m84m(r_L);
$46: r_B:=m38m; $47: m84m(r_A);
$48: begin r_C:=r_B; m25m; end;
$49:m25m; 
$4A: begin r_C:=r_D; m25m; end;
$4B: begin r_C:=r_E; m25m; end;
$4C: begin r_C:=r_H; m25m; end;
$4D: begin r_C:=r_L; m25m; end;
$4E: begin r_C:=m38m; end;
$4F: begin r_C:=r_A; m25m; end;
$50: begin r_D:=r_B; m25m; end;
$51: begin r_D:=r_C; m25m; end;
$53: begin r_D:=r_E; m25m; end;
$54: begin r_D:=r_H; m25m; end;
$55: begin r_D:=r_L; m25m; end;
$56: begin r_D:=m38m; end;
$57: begin r_D:=r_A; m25m; end;
$58: begin r_E:=r_B; m25m; end;
$59: begin r_E:=r_C; m25m; end;
$5A: begin r_E:=r_D; m25m; end;
$5C: begin r_E:=r_H; m25m; end;
$5D: begin r_E:=r_L; m25m; end;
$5E: begin r_E:=m38m; end;
$5F: begin r_E:=r_A; m25m; end;
$60: begin r_H:=r_B; m25m; end;
$61: begin r_H:=r_C; m25m; end;
$62: begin r_H:=r_D; m25m; end;
$63: begin r_H:=r_E; m25m; end;
$65: begin r_H:=r_L; m25m; end;
$66: begin r_H:=m38m; end;
$67: begin r_H:=r_A; m25m; end;
$68: begin r_L:=r_B; m25m; end;
$69: begin r_L:=r_C; m25m; end;
$6A: begin r_L:=r_D; m25m; end;
$6B: begin r_L:=r_E; m25m; end;
$6C: begin r_L:=r_H; m25m; end;
$6E: begin r_L:=m38m; end;
$6F: begin r_L:=r_A; m25m; end;
$70: begin m44m(r_B); m31m; end;
$71: begin m44m(r_C); m31m; end;
$72: begin m44m(r_D); m31m; end;
$73: begin m44m(r_E); m31m; end;
$74: begin m44m(r_H); m31m; end;
$75: begin m44m(r_L); m31m; end;
$76: begin m27m; end;
$77: begin m44m(r_A); m31m; end;
$78: begin r_A:=r_B; m25m; end;
$79: begin r_A:=r_C; m25m; end;
$7A: begin r_A:=r_D; m25m; end;
$7B: begin r_A:=r_E; m25m; end;
$7C: begin r_A:=r_H; m25m; end;
$7D: begin r_A:=r_L; m25m; end;
$7E: begin r_A:=m38m; end;
$80: begin tmp2:=r_A+r_B; m08m; m36m(r_B); m32m; r_A:=(tmp2 and $FF); m27m; end;

$81:m70m(r_C);$82:m70m(r_D);$83:m70m(r_E);$84:m70m(r_H);$85:m70m(r_L);

$86: begin m74m; tmp2:=r_A+tmp1; m08m; m36m(tmp1); m32m; m04m; m31m; end;
$87: m70m(r_A);
$88:m71m(r_B); $89:m71m(r_C); $8A:m71m(r_D);$8B:m71m(r_E);
$8C: begin m73m(r_H); if (tmp2>$FF) then begin m65m; end; m04m; m27m; end;
$8D:m71m(r_L);
$8E: begin m74m; m73m(tmp1); m32m; m04m; m31m; end;
$8F:m71m(r_A); $90:m40m(r_B); $91:m40m(r_C);$92:m40m(r_D); $93:m40m(r_E); $94:m40m(r_H);
$95: begin m85m(r_A-r_L); m09m; if (r_A<r_L) then begin m65m; end; m36m(r_L); m35m; end;
$96: begin m74m; m75m; m09m; if (r_A<tmp1) then begin m13m; end; m36m(tmp1); m06m; m31m; end;
$97: begin m10m; r_A:=0; m27m; end;
$98: m41m(r_B);$99: m41m(r_C);$9A: m41m(r_D);$9B: m41m(r_E);$9C: m41m(r_H);$9D: m41m(r_L);

$9E: begin m74m; if m57m then tmp3:=1 else tmp3:=0;
 m85m(r_A-tmp1-tmp3); m09m; if (r_A<tmp1+tmp3) then begin m13m; end;
 m36m(tmp1); m06m; m31m; end;

$9F: begin if m57m then tmp2:=$FF else tmp2:=0; m09m; if (tmp2<>0) then
 begin r_F:=r_F or (f_A or f_C); end; m35m; end;

$A0: begin m61m(r_B); m26m; end;
$A1: begin m61m(r_C); m26m; end;
$A2: begin m61m(r_D); m26m; end;
$A3: begin m61m(r_E); m26m; end;
$A4: begin m61m(r_H); m26m; end;
$A5: begin m61m(r_L); m26m; end;
$A6: begin m74m; m61m(tmp1); m11m; m31m; end;
$A7: begin m61m(r_A); m26m; end;

$A8: begin m67m(r_B); m26m; end;
$A9: begin m67m(r_C); m26m; end;
$AA: begin m67m(r_D); m26m; end;
$AB: begin m67m(r_E); m26m; end;
$AC: begin m67m(r_H); m26m; end;
$AD: begin m67m(r_L); m26m; end;
$AE: begin m74m; m67m(tmp1); m11m; m17m; m14m; end; $AF: begin r_A:=0; m26m; end;

$B0: begin m64m(r_B); m26m; end;
$B1: begin m64m(r_C); m26m; end;
$B2: begin m64m(r_D); m26m; end;
$B3: begin m64m(r_E); m26m; end;
$B4: begin m64m(r_H); m26m; end;
$B5: begin m64m(r_L); m26m; end;
$B6: begin m74m; m64m(tmp1); m11m; m31m; end;
$B7: begin m64m(r_A); m26m; end;

$B8:m63m(r_b); $B9:m63m(r_c); $BA:m63m(r_d); $BB:m63m(r_e); $BC:m63m(r_h);$BD:m63m(r_l);

$BE: begin m74m; m75m; m09m; if (r_A<tmp1) then begin m13m; end; m36m(tmp1); m31m; end;
$BF: begin m10m; m27m; end;
$C0: begin if ((r_F and f_Z)<>0) then begin m25m; end else begin m82m; end; end;
$C1: begin r_C:=do_read(r_SP); r_B:=do_read(r_SP+1); m66m; m34m; end;

$C2: begin if ((r_F and f_Z)<>0) then begin m03m; end
 else begin r_PC:=m29m+((m28m shl 8)); m19m; end; end;

$C3: begin r_PC:=m29m+((m28m shl 8)); m19m; end;
$C4: begin if ((r_F and f_Z)<>0) then begin m78m; end else
 begin tmp1:=m29m+((m28m shl 8)); m50m; m02m; m56m; do_write(r_SP+1,m55m); m51m; end; end;

$C5: begin m50m; do_write(r_SP,r_C); do_write(r_SP+1,r_B); m20m; m14m; end;

$C6: begin m47m; tmp2:=r_A+tmp1; m08m; m36m(tmp1);
if (tmp2>$FF) then begin m65m; end; m04m; m33m; end;

$C7: begin m50m; m14m; m56m; do_write(r_SP+1,m55m); r_PC:=0*8; m20m; end;

$C8: begin if m60m then begin m25m; end else begin m82m; end; end;
$C9: begin m82m; end;
$CA: begin if m60m then begin m03m; end else begin m77m; end; end;
$CB: m77m;
$CC: begin if m60m then begin m78m; end else m68m; end;
$CD: m68m;
$CE: begin m47m; m73m(tmp1); if (tmp2>$FF) then begin m65m; end; m04m; m33m; end;
$CF: begin m50m; m14m; m56m; do_write(r_SP+1,m55m); r_PC:=1*8; m20m; end;
$D0: begin if m57m then begin m25m; end else begin m82m; end end;
$D1: begin r_E:=do_read(r_SP); r_D:=do_read(r_SP+1); m66m; m34m; end;
$D2: begin if m57m then begin m03m; end else begin m77m; end; end;
$D3: begin do_output(m29m,r_A); m19m; m15m; end;
$D4: begin if m57m then begin m78m; end else begin m68m; end; end;
$D5: begin m50m; do_write(r_SP,r_E); do_write(r_SP+1,r_D); m20m; m14m; end;
$D6: begin m47m; m75m; m09m; m76m; m36m(tmp1); m06m; m33m; end;
$D7: begin m50m; m14m; m56m; do_write(r_SP+1,m55m); r_PC:=2*8; m20m; end;
$D8: begin if m59m then begin m25m; end else begin m82m; end; end;
$D9: begin begin m82m; end; end;
$DA: begin if m59m then begin m03m; end else begin m77m; end; end;
$DB: begin r_A:=do_input(m29m); m19m; m15m; end;
$DC: begin if m59m then begin m78m; end else begin m68m; end; end;

$DD: m68m;$ED: m68m;$FD: m68m;

$DE: begin m47m; if m57m then tmp3:=1 else tmp3:=0;
 m85m(r_A-tmp1-tmp3); m09m; if (r_A<tmp1+tmp3) then begin
 m65m; end; m36m(tmp1); m06m; m33m; end;

$DF: begin m50m; m14m; m56m; do_write(r_SP+1,m55m); r_PC:=3*8; m20m; end;
$E0: begin if m79m then begin m25m; end else begin m82m; end ; end;
$E1: begin r_L:=do_read(r_SP); r_H:=do_read(r_SP+1); m66m; m34m; end;
$E2: begin if m79m then begin m03m; end else begin m77m; end; end;

$E3: begin tmp1:=do_read(r_SP); do_write(r_SP,r_L); r_L:=tmp1;
 tmp1:=do_read(r_SP+1); do_write(r_SP+1,r_H); r_H:=tmp1; clock:=clock+18; m14m; end;

$E4: begin if m79m then begin m78m; end else begin m68m; end; end;
$E5: begin m50m; do_write(r_SP,r_L); do_write(r_SP+1,r_H); m20m; m14m; end;
$E6: begin m61m(m29m); m11m; m33m; end;
$E7: begin m50m; m14m; m56m; do_write(r_SP+1,m55m); r_PC:=4*8; m20m; end;
$E8: begin if m58m then begin m25m; end else begin m82m; end; end;
$E9: begin r_PC:=(r_H shl 8)+r_L; m18m; end;
$EA: begin if m58m then begin m03m; end else begin m77m; end; end;
$EB: begin tmp1:=r_D; r_D:=r_H; r_H:=tmp1; tmp1:=r_E; r_E:=r_L; r_L:=tmp1; m16m; m14m; end;
$EC: begin if m58m then begin m78m; end else begin m68m; end; end;
$EE: begin r_A:= r_A xor m29m; m11m; m33m; end;
$EF: begin m50m; m14m; m56m; do_write(r_SP+1,m55m); r_PC:=5*8; m20m; end;
$F0: begin if m53m then begin m25m; end else begin m82m; end; end;
$F1: begin r_F:=do_read(r_SP); r_A:=do_read(r_SP+1); m66m; m34m; end;
$F2: begin if m53m then begin m03m; end else begin m77m; end; end;
$F4: begin if m53m then begin m78m; end else begin m68m; end; end;
$F5: begin m50m; do_write(r_SP,r_F); do_write(r_SP+1,r_A); m20m; m14m; end;
$F6: begin m64m(m29m); m11m; m33m; end;
$F7: begin m50m; m14m; m56m; do_write(r_SP+1,m55m); r_PC:=6*8; m20m; end;
$F8: begin if m54m then begin m25m; end else begin m82m; end; end;
$F9: begin r_SP:=(r_H shl 8)+r_L; m25m; end;
$FA: begin if m54m then begin m03m; end else begin m77m; end; end;
$FC: begin if m54m then begin m78m; end else begin m68m; end; end;
$FE: begin m47m; m75m; m09m; m76m; m36m(tmp1); m17m; m15m; end;
$FF: begin m50m; m14m; m56m; do_write(r_SP+1,m55m); r_PC:=7*8; m20m; end
 end;
end;

rgA:=Cardinal(r_A);rgB:=Cardinal(r_b);rgC:=Cardinal(r_c);rgD:=Cardinal(r_d);
rgE:=Cardinal(r_e);rgH:=Cardinal(r_H);rgL:=Cardinal(r_L);rgF:=Cardinal(r_F);
rgPC:=Cardinal(r_PC);rgSP:=Cardinal(r_SP);

fS:=Cardinal(f_S);fZ:=Cardinal(f_Z);f5:=Cardinal(f_5);fA:=Cardinal(f_A);
f3:=Cardinal(f_3);fP:=Cardinal(f_P);f1:=Cardinal(f_1);fC:=Cardinal(f_C);
{$R+}
end;



procedure TMainForm.draw_screen1;

Begin
 {$R-}
//if FullScreen1.Checked then // на весь экран или нет
MainForm.Canvas.StretchDraw(rect(0,0,MainForm.Width-0,MainForm.Height-30), gamecanvas)
//else
//MainForm.Canvas.Draw(0,0,gamecanvas);
 {$R+}
end;



//function col_index(port : Cardinal; color : Cardinal): Cardinal; // колор в зависимоти от порта С

var col_index_port,col_index_color,col_index_result:cardinal;
procedure TMainForm.col_index;
Var port,color,result_:Cardinal;
begin
 {$R-}
port:=col_index_port; color:=col_index_color;
 Result_:=LVColBlack;
 if ((port and $40)<>0) then Result_:= (Result_ xor LVColBlue);
 if ((port and $20)<>0) then Result_:= (Result_ xor LVColLime);
 if ((port and $10)<>0) then Result_:= (Result_ xor LVColRed);
// case color of
 if color = LVColBlack then
 begin
 if ((port and $08)=0) then
 begin Result_:= (Result_ xor LVColRed); end;
 if ((port and $04)=0) then
 begin Result_:= (Result_ xor LVColBlue); end;
 end else
 if color = LVColLime then begin Result_:= (Result_ xor LVColLime); end else
 if color = LVColRed then begin Result_:= (Result_ xor LVColRed);
 if ((port and $02)=0) then
 begin Result_:= (Result_ xor LVColLime); end; end else
 if color = LVColBlue then begin Result_:= (Result_ xor LVColBlue);
 if ((port and $01)=0) then
 begin Result_:= (Result_ xor LVColRed); end; end;

col_index_result:=result_;
 {$R+}
end;



var My_col_inp,My_col_result:Cardinal;

Procedure TMainForm.My_col2;
var inp,result:Cardinal;
begin
 {$R-}
inp:=My_col_inp;
if inp=0 then My_col_result:=LVColBlack else
if inp=1 then My_col_result:=LVColLime else
if inp=2 then My_col_result:=LVColBlue else
if inp=3 then My_col_result:=LVColRed else
 {$R+}
end;


var SupCol2_c1,SupCol2_b,SupCol2_x:Cardinal;

var SupCol2_Result:Cardinal;
Procedure TMainForm.SupCol2;
 Var c1,b,x,_Result:Cardinal;
 pix:Cardinal;
begin
 {$R-}
 c1:=SupCol2_c1; b:=SupCol2_b; x:=SupCol2_x; pix:=0;
 case x of
 1: begin
 if (b and 128)=128 then pix:=pix+1;
 if (b and 8)=8 then pix:=pix+2;
 end;
 2: begin
 if (b and 64)=64 then pix:=pix+1;
 if (b and 4)=4 then pix:=pix+2;
 end;
 3: begin
 if (b and 32)=32 then pix:=pix+1;
 if (b and 2)=2 then pix:=pix+2;
 end;
 4: begin
 if (b and 16)=16 then pix:=pix+1;
 if (b and 1)=1 then pix:=pix+2;
 end;
 end;
 col_index_port:=c1;
 My_Col_inp:=pix;My_Col2;
 col_index_color:=My_col_result;
 col_index;SupCol2_Result:=col_index_result;
 {$R+}
end;

var draw_screen2_i:Cardinal;

procedure TMainForm.draw_screen2; //Рисуем с video на экран (Форму)

var vertX,gorY : Cardinal;

begin

 vertX:= (draw_screen2_i mod 64)*4; gorY:=(draw_screen2_i div 64)*1;

 Rports_a:=$C1;Rports;

 SupCol2_c1:=Rports_result;Rvideo_a:=draw_screen2_i;Rvideo;

 SupCol2_b:=Rvideo_result;

 SupCol2_x:=1;SupCol2;
 gamecanvas.Canvas.Pixels[vertX,gorY]:= SupCol2_Result;
 SupCol2_x:=2;SupCol2;
 gamecanvas.Canvas.Pixels[vertX+1,gorY]:=SupCol2_Result;
 SupCol2_x:=3;SupCol2;
 gamecanvas.Canvas.Pixels[vertX+2,gorY]:=SupCol2_Result;
 SupCol2_x:=4;SupCol2;
 gamecanvas.Canvas.Pixels[vertX+3,gorY]:=SupCol2_Result;
end;

procedure TMainForm.draw_screen; //Рисуем с video на экран (Форму)

var i:Cardinal;

begin
{$R-}

for i:=0 to $3fff do begin

 Rvideo_a:=i;Rvideo;
 RVideoDirty_a:=i;RVideoDirty;
 if Rvideo_Result<>RVideoDirty_Result then //сравниваем значения , а есть ли изменения
 begin
 draw_screen2_i:=i; draw_screen2;
 Rvideo_a:=i;Rvideo;
 WVideoDirty_a:=i; WVideoDirty_b:=Rvideo_Result;WVideoDirty;
 end;
 end;
draw_screen1;
{$R+}
end;




procedure TMainForm.FirstPusk; //первый запуск
 begin
 // создадим канву для рисования
 gamecanvas:=tbitmap.Create;
 gamecanvas.Width:=256;
 gamecanvas.Height:=256;

 ResetComp; // первоночальный сброс всего
 TimerMain.Enabled:=true; // запускаем основной таймер
end;

function TMainForm.readmask (keynum: word): word; // маска клавы
begin
result:= $72FF;
case keynum of
 8: begin result:= $23FF end; // BCK
 13: begin result:= $13FF end; // ENTER
	 16: begin result:= $70FF end; // SHIFT
 32: begin result:= $30FF end; // SPC

 37: begin result:= $FF32 end; // <-
 38: begin result:= $FF31 end; // UP
 39: begin result:= $FF30 end; // ->
 40: begin result:= $FF33 end; // DOWN

 48: begin result:= $06FF end; // 0
	 49: begin result:= $47FF end; // 1
	 50: begin result:= $46FF end; // 2
 	 51: begin result:= $45FF end; // 3
 	 52: begin result:= $44FF end; // 4
 	 53: begin result:= $43FF end; // 5
 	 54: begin result:= $00FF end; // 6
 	 55: begin result:= $01FF end; // 7
 	 56: begin result:= $02FF end; // 8
 	 57: begin result:= $07FF end; // 9

 	 65: begin result:= $64FF end; // A
 66: begin result:= $31FF end; // B
 67: begin result:= $57FF end; // C
 68: begin result:= $27FF end; // D
 69: begin result:= $54FF end; // E
 70: begin result:= $67FF end; // F
 71: begin result:= $10FF end; // G
 	 72: begin result:= $16FF end; // H
 	 73: begin result:= $75FF end; // I
 	 74: begin result:= $52FF end; // J
 75: begin result:= $55FF end; // K
 	 76: begin result:= $22FF end; // L
 	 77: begin result:= $76FF end; // M
 	 78: begin result:= $53FF end; // N
 	 79: begin result:= $21FF end; // O
 	 80: begin result:= $63FF end; // P
 	 81: begin result:= $71FF end; // Q
 82: begin result:= $20FF end; // R
 	 83: begin result:= $77FF end; // S
 	 84: begin result:= $74FF end; // T
 85: begin result:= $56FF end; // U
 	 86: begin result:= $26FF end; // V
 	 87: begin result:= $65FF end; // W
 	 88: begin result:= $73FF end; // X
 	 89: begin result:= $66FF end; // Y
 	 90: begin result:= $17FF end; // Z

 	 107: begin result:= $05FF end; // =/+ -> =/-
 	 109: begin result:= $05FF end; // -/_ -> =/-

 	 114: begin result:= $FF23 end; // F3
 	 115: begin result:= $FF22 end; // F4
 	 116: begin result:= $FF21 end; // F5

 	 36: begin result:= $FF20 end; // Home

 	 219: begin result:= $11FF end; // [
 	 221: begin result:= $12FF end; // ]
 	 190: begin result:= $24FF end; // .
 	 188: begin result:= $37FF end; // ,
 	 192: begin result:= $72FF end; //
end;

end;

procedure TMainForm.FormActivate(Sender: TObject);
begin
if FPusk then // а это первый ли запуск
 begin
 FPusk:=false;
 FirstPusk;
 end;
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
DragAcceptFiles(MainForm.Handle, true); // сделаем драг анд дроб :)
FPusk:=true; // запомним первый запуск
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin
DragAcceptFiles(Handle, False);

end;

procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word; //опрос клавы
 Shift: TShiftState);
begin
 kbd(readmask(key),true); // нажали
// i8080_do_opcodes(opcodes_to_run);
end;

procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
 kbd(readmask(key),false); // отпустии
end;

procedure TMainForm.TimerMainTimer(Sender: TObject); // основной таймер
var j,a: word;i: integer;s: string;
begin
//if (pause) then begin exit; end; // если пауза курим бамбук :)
 i8080_do_opcodes(opcodes_to_run);
 draw_screen;
end;

procedure TMainForm.ResetComp;
begin
// rgB := 0; rgC := 0; rgD := 0; rgE := 0; rgH := 0; rgL := 0; rgA := 0; rgF := 0;
// rgPC := 0; rgSP := 0;
// pause := false;
// fS := (1 SHL 7); fZ :=( 1 SHL 6); f5 := (1 SHL 5); fA := (1 SHL 4); f3 := (1 SHL 3);
// fP := (1 SHL 2); f1 := (1 SHL 1); fC := (1 SHL 0);
 BasicStack := $AFC1; BasicHotEntry := $02FD; BasicProgBegin := $0243; BasicProgEnd := $0245;

fillcharVideoDirty;
//i8080_init;
// reset1();
// load_bios();
//rgPC:=$C000;
// i8080_do_opcodes(0);
TimerMain.Interval:=(1000 div FPS);
end;

procedure TMainForm.ResetCPU1Click(Sender: TObject);
begin
ResetComp;
end;

end.

Вы здесь » Середовище програмування MADL » КР-580 » SAS Emulator. ВихКод. FASM