home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / z / zsim20.zip / Z80IFACE.ASM < prev    next >
Assembly Source File  |  1992-12-02  |  4KB  |  184 lines

  1. ;
  2. ; Interface to use the Z80 simulator without cpmbios
  3. ;
  4. ; (c) 1992 Jürgen Weber
  5. ;
  6. ; Assemble:   tasm /mx Z80IFACE
  7. ; (without option /mx there would be the upper case
  8. ;  a label _EMULATE which is not equal to emulate() )
  9.  
  10. EXTRN bios88ret:FAR,ctrl_break_req:FAR,interrupt_request:FAR,nmi_irq:FAR
  11. EXTRN set_read_dist:FAR,set_write_dist:FAR
  12.  
  13. PUBLIC bios88,prg_exit,port_in,port_out,get_rand
  14. PUBLIC _emulate,_genint,_genhalt,get_rand,port_out,port_in
  15. PUBLIC _setcfg
  16.  
  17. DGROUP    GROUP _DATA,_BSS
  18. _DATA SEGMENT WORD PUBLIC 'DATA'
  19. _DATA ENDS
  20. _BSS SEGMENT WORD PUBLIC 'BSS'
  21. _BSS ENDS
  22.  
  23. _TEXT segment para public 'Code'
  24. assume cs:_TEXT,es:nothing,ds:nothing
  25.  
  26.  
  27. calln_hnd dw 0,0
  28. halt_hnd dw 0,0
  29.  
  30. ; _emulate(unsigned z80seg,
  31. ;          void far (*calln_handler)(int far *),
  32. ;          void far (*halt_handler)(void))
  33.  
  34. spsave dw (?)
  35.  
  36. _emulate proc far
  37. ARG z80seg:WORD,calln_handler:DWORD,halt_handler:DWORD
  38.         mov cs:spsave,sp
  39.         push bp
  40.         mov bp,sp
  41.         lds ax,calln_handler
  42.         mov cs:calln_hnd+0,ax
  43.         mov ax,ds
  44.         mov cs:calln_hnd+2,ax
  45.         lds ax,halt_handler
  46.         mov cs:halt_hnd+0,ax
  47.         mov ax,ds
  48.         mov cs:halt_hnd+2,ax
  49.         mov ax,[z80seg]
  50.         pop bp
  51.         mov es,ax
  52.         mov ds,ax
  53.         mov si,0      ; start at 0
  54.         jmp bios88ret
  55. emexit:
  56.         mov ax,DGROUP
  57.         mov ds,ax
  58.         mov sp,cs:spsave
  59.         ret
  60. _emulate endp
  61.  
  62. ; call this function to generate an interrupt of the z80
  63. ; for example you could hook the timer interrupt to
  64. ; call this function
  65. ; void genint(void)
  66. _genint proc far
  67. ARG databus:WORD
  68.        push bp
  69.        mov bp,sp
  70.        mov ax,[databus]  ; the value in al simulates the value put
  71.        pop bp            ; on the data bus at z80 irq
  72.        call interrupt_request
  73.        ret
  74. _genint endp
  75.  
  76.  
  77. ; call this function to force the z80 to execute HALT (-> prg_exit)
  78. ; for example you could hook the ctrl_break interrupt to
  79. ; call this function
  80. ; void genhalt(void)
  81. _genhalt proc far
  82.        call ctrl_break_req
  83.        ret
  84. _genhalt endp
  85.  
  86. ; bios88 is called if the bytes ED ED xx are met
  87. ; use ED ED xx to execute an operating system call xx (al=xx)
  88. ; if xx==0ffh goto emulation exit
  89. bios88 proc far
  90. local rsi,rdx,rcx,rbx,rax:WORD=AUTO_SIZE
  91.         cmp al,0ffh
  92.         jz emexit     ; end emulation
  93.         push bp
  94.         mov bp,sp
  95.         sub sp,AUTO_SIZE
  96.         mov di,sp
  97.         push ds
  98.         push es
  99.         mov rax,ax
  100.         mov rbx,bx
  101.         mov rcx,cx
  102.         mov rdx,dx
  103.         mov rsi,si
  104.         push ss  ; int far *regs
  105.         push di  ; stack grows downwards
  106.         mov ax,DGROUP
  107.         mov ds,ax
  108. ; void far calln_handler(int far *regs);
  109.         call dword ptr cs:[calln_hnd]
  110.         add sp,4
  111.         mov ax,rax
  112.         mov bx,rbx
  113.         mov cx,rcx
  114.         mov dx,rdx
  115.         mov si,rsi
  116.         pop es
  117.         pop ds
  118.         mov sp,bp
  119.         pop bp
  120.         jmp bios88ret
  121. bios88 endp
  122.  
  123. ; prg_exit is called, if a HALT operation is executed
  124. prg_exit proc far
  125.       push ds
  126.       push es
  127.       push si
  128.       push ax
  129.       push bx
  130.       push cx
  131.       push dx ; save all registers
  132.         mov ax,DGROUP
  133.         mov ds,ax
  134. ; void far halt_handler(void);
  135.        call dword ptr cs:[halt_hnd]
  136.      pop dx
  137.      pop cx
  138.      pop bx
  139.      pop ax
  140.      pop si
  141.      pop es
  142.      pop ds
  143.      ret
  144. prg_exit endp
  145.  
  146. port_in proc far
  147.         mov al,0ffh
  148.         ret
  149. port_in endp
  150.  
  151. port_out proc far
  152.         ret
  153. port_out endp
  154.  
  155. get_rand proc far
  156.         mov al,0
  157.         ret
  158. get_rand endp
  159.  
  160.  
  161. ; _setcfg(unsigned rdseg,rdoffs,wrseg,wroffs);
  162. ; all read accesses are done in segment rdseg by adding rdoffs
  163. ; all write accesses are done in segment wrseg by adding wroffs
  164.  
  165. _setcfg proc far
  166. ARG rdseg:WORD,rdoffs:WORD,wrseg:WORD,wroffs:WORD
  167.         push bp
  168.         mov bp,sp
  169.         mov bx,rdseg
  170.         mov ax,rdoffs
  171.         call set_read_dist
  172.         mov bx,wrseg
  173.         mov ax,wroffs
  174.         call set_write_dist
  175.  
  176.         pop bp
  177.         ret
  178. _setcfg endp
  179.  
  180. _TEXT ends
  181.  
  182. end
  183.  
  184.