Digital Research
This commit is contained in:
2020-11-06 18:50:37 +01:00
parent 621ed8ccaf
commit 31738079c4
8481 changed files with 1888323 additions and 0 deletions

View File

@@ -0,0 +1,218 @@
#*******************************************************************************
#* z80em86 Makefile *
#* A Z80 CPU emulator coded in Intel 86 assembly language *
#* *
#* Copyright (C) 1992-2009 Stewart Kay *
#*******************************************************************************
#
#===============================================================================
# REVISION HISTORY (Most recent at top)
#===============================================================================
# v1.0.0 - S.J.Kay 13/2/2009
# --------------------------
# Created initial Makefile.
#
#===============================================================================
# How to use this GNU make file.
#===============================================================================
# make help will show the options available.
#
#===============================================================================
# Requirements
#===============================================================================
# Requirements:
# - NASM assembler (Netwide Assembler)
# - ALINK cross linker (will be downloaded and built during the make process)
#===============================================================================
# Overrides
#===============================================================================
.SUFFIXES:
TOPDIR=..
#===============================================================================
# Application specific definitions
#===============================================================================
APP=z80em86
VERSION=1.0.1
TITLE=z80em86
# Set the debugging level
OPT_DEBUG=0
# Values passed as defines when compiling
APPVER=\"$(VERSION)\"
APPIDSTR=\"$(APP)\"
# Object files
OBJA=./arith16.obj ./bit.obj ./control.obj ./function.obj ./insthand.obj
OBJA+=./jump.obj ./load8.obj ./main.obj ./rotate.obj ./table.obj ./window.obj
OBJA+=./arith8.obj ./call.obj ./exchange.obj ./hardware.obj ./io.obj ./load16.obj
OBJA+=./macros.obj ./res.obj ./set.obj ./video.obj
# Dependencies
DEPENDENCIES=macros.asm Makefile
HAVE_DOSEMU=$(wildcard ~/.dosemu/drive_c)
Z80HDD=~/.dosemu/drive_c/$(APP)/z80hdd.exe
#===============================================================================
# Cross compile and link.
#
# -O2 is needed to optimise code like TASM does, there does not appear to be a
# way to turn it off in TASM.
#===============================================================================
XOBJA=$(OBJA:./%=build/%)
LOBJA=$(XOBJA:%.obj=%.lst)
ifeq ($(OPT_DEBUG),1)
DEBUG=
OPT=
else
DEBUG=
OPT=-O2
endif
NASM=nasm
LINK=../alink/alink
AFLAGS=$(DEBUG) $(OPT) -f obj
AINC=
ALIB=
ADEF=-DAPPVER=$(APPVER) -DAPPIDSTR=$(APPIDSTR)
build/$(APP).exe: $(LINK) $(XOBJA) $(Z80HDD)
$(LINK) $(XOBJA) -o build/$(APP).exe -m
build/%.obj: %.asm $(DEPENDENCIES)
@[ -d build ] || mkdir build
$(NASM) $(AFLAGS) $(ADEF) $(*).asm -o build/$(*).obj -l build/$(*).lst
$(LINK):
sh ../scripts/build_alink.sh ../alink ../temp \
http://alink.sourceforge.net/files/alinksrc.zip
ifneq ($(HAVE_DOSEMU),)
$(Z80HDD): z80hdd.pas
@[ -d ~/.dosemu/drive_c/$(APP) ] || mkdir ~/.dosemu/drive_c/$(APP)
cp z80hdd.pas ~/.dosemu/drive_c/$(APP)
dosemu -dumb "cd $(APP)|tpc z80hdd.pas"
cp ~/.dosemu/drive_c/$(APP)/z80hdd.exe build/
else
$(Z80HDD):
@echo "No '~/.dosemu/drive_c/' dosemu home account was located"
@echo "Can't create Z80HDD.EXE"
endif
#===============================================================================
# General maintenance
#===============================================================================
clean:
rm -f $(XOBJA) $(LOBJA) build/$(APP).exe build/$(APP).map \
$(TOPDIR)/distributions/$(APP)-$(VERSION).tar.gz \
$(TOPDIR)/distributions/$(APP)-$(VERSION)-dos.zip \
$(Z80HDD)
cleanall: clean
rm -Rf build/
rm -Rf $(LINK)
#===============================================================================
# Install and remove installed files
#===============================================================================
ifneq ($(HAVE_DOSEMU),)
install:
@[ -d ~/.dosemu/drive_c/$(APP) ] || mkdir ~/.dosemu/drive_c/$(APP)
cp build/$(APP).exe ~/.dosemu/drive_c/$(APP)/
uninstall:
rm ~/.dosemu/drive_c/$(APP)/$(APP).exe
else
install:
@echo "No '~/.dosemu/drive_c/' dosemu home account was located"
uninstall:
@echo "No '~/.dosemu/drive_c/' dosemu home account was located"
endif
#===============================================================================
# Run the program under dosemu.
#
# A bootable Z80HDD.DSK image is required in '~/.dosemu/drive_c/z80em86/'
# for non floppy drive booting and is the default unless a floppy drive is
# specified.
#
# If the Z80HDD.DSK is not found the user will be prompted for a floppy
# disk in drive A:
#===============================================================================
HAVE_INSTALL=$(wildcard ~/.dosemu/drive_c/$(APP)/$(APP).exe)
ifneq ($(HAVE_INSTALL),)
run:
dosemu "cd $(APP)|z80em86"
runa:
dosemu "cd $(APP)|z80em86 -a"
runb:
dosemu "cd $(APP)|z80em86 -b"
else
run:
@echo "$(APP).exe has not been installed"
runa:
@echo "$(APP).exe has not been installed"
runb:
@echo "$(APP).exe has not been installed"
endif
#===============================================================================
# Help
#===============================================================================
help:
@echo "This is the $(APP) v$(VERSION) Z80 emulator GNU makefile"
@echo ""
@echo "Specify one of the following:"
@echo "make cross compiled DOS build"
@echo "make clean removes build and distribution files"
@echo "make cleanall cleans and removes alink generated files"
@echo "make install install files under dosemu"
@echo "make uninstall uninstall files under dosemu"
@echo "make run run booting Z80HDD.DSK under dosemu"
@echo "make runa run forcing booting A: under dosemu"
@echo "make runb run forcing booting B: under dosemu"
@echo "make help this help information"
@echo ""
@echo "Packaging system only:"
@echo "make srcdist make source distribution"
@echo "make alldist make source and DOS binary distribution"
@echo "make doszipdist make DOS ZIP binary distribution"
@echo "make upload upload distribution packages"
#===============================================================================
# Create source distribution.
#===============================================================================
srcdist:
cd $(TOPDIR) && make srcdist V=$(VERSION)
#===============================================================================
# Create all distributions.
#===============================================================================
alldist:
cd $(TOPDIR) && make alldist V=$(VERSION)
#===============================================================================
# Create a DOS binary ZIP file distribution.
#===============================================================================
doszipdist:
cd $(TOPDIR) && make doszipdist V=$(VERSION)
#===============================================================================
# Upload all the distribution files.
#===============================================================================
upload:
cd $(TOPDIR) && make upload_to_sf V=$(VERSION)

View File

@@ -0,0 +1,470 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* 16-bit Arithmetic Group *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 10 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Added 'align=16' to all SEGMENT declarations. (nasm def is align=1)
;
; v1.00 - 29 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
SEGMENT Z80map public align=16
Z80:
SEGMENT .code public align=16
GLOBAL Z_ADxbc, Z_ADxde, Z_INCx, Z_ADxx, Z_DECx
GLOBAL Z_ADxsp
GLOBAL Z_ADybc, Z_ADyde, Z_INCy, Z_ADyy, Z_DECy
GLOBAL Z_ADysp
GLOBAL Z_SChlbc, Z_AChlbc, Z_SChlde, Z_AChlde
GLOBAL Z_SChlhl, Z_AChlhl, Z_SChlsp, Z_AChlsp
GLOBAL Z_INCbc, Z_INCde, Z_INChl, Z_DECbc, Z_DECde, Z_DEChl
GLOBAL Z_INCsp, Z_DECsp
GLOBAL Z_ADhlbc, Z_ADhlde, Z_ADhlhl, Z_ADhlsp
; declared in INSTHAND.ASM
EXTERN Z80IX, Z80IY, Z80SP, FlagN
%include "macros.asm"
;***********************************************************
;* ADD HL,BC Flags: S Z - H - P/V N C *
;* . . x x x . 0 ^ *
;***********************************************************
Z_ADhlbc:
mov BYTE [FlagN],0
mov di,dx ;save value in reg DX
lahf
and ah,11111110b
mov dh,ah
add bx,cx
lahf
and ah,00000001b
or ah,dh
mov dx,di ;restore value to reg DX
XinstB
;***********************************************************
;* ADD HL,DE Flags: S Z - H - P/V N C *
;* . . x x x . 0 ^ *
;***********************************************************
Z_ADhlde:
mov BYTE [FlagN],0
mov di,cx ;save value in reg CX
lahf
and ah,11111110b
mov ch,ah
add bx,dx
lahf
and ah,00000001b
or ah,ch
mov cx,di ;restore value to reg CX
XinstB
;***********************************************************
;* ADD HL,HL Flags: S Z - H - P/V N C *
;* . . x x x . 0 ^ *
;***********************************************************
Z_ADhlhl:
mov BYTE [FlagN],0
mov di,dx ;save value in reg DX
lahf
and ah,11111110b
mov dh,ah
add bx,bx
lahf
and ah,00000001b
or ah,dh
mov dx,di ;restore value to reg DX
XinstB
;***********************************************************
;* ADD HL,SP Flags: S Z - H - P/V N C *
;* . . x x x . 0 ^ *
;***********************************************************
Z_ADhlsp:
mov BYTE [FlagN],0
mov di,dx ;save value in reg DX
lahf
and ah,11111110b
mov dh,ah
add bx,[Z80SP]
lahf
and ah,00000001b
or ah,dh
mov dx,di ;restore value to reg DX
XinstB
;***********************************************************
;* ADD IX,BC Flags: S Z - H - P/V N C *
;* . . x x x . 0 ^ *
;***********************************************************
Z_ADxbc:
mov BYTE [FlagN],0
mov di,dx ;save value in reg DX
lahf
and ah,11111110b
mov dh,ah
add [Z80IX],cx
lahf
and ah,00000001b
or ah,dh
mov dx,di ;restore value to reg DX
XinstB
;***********************************************************
;* ADD IX,DE Flags: S Z - H - P/V N C *
;* . . x x x . 0 ^ *
;***********************************************************
Z_ADxde:
mov BYTE [FlagN],0
mov di,cx ;save value in reg CX
lahf
and ah,11111110b
mov ch,ah
add [Z80IX],dx
lahf
and ah,00000001b
or ah,ch
mov cx,di ;restore value to reg CX
XinstB
;***********************************************************
;* ADD IX,IX Flags: S Z - H - P/V N C *
;* . . x x x . 0 ^ *
;***********************************************************
Z_ADxx:
mov BYTE [FlagN],0
mov di,dx ;save value in reg DX
lahf
and ah,11111110b
mov dh,ah
mov si,[Z80IX]
add [Z80IX],si
lahf
and ah,00000001b
or ah,dh
mov dx,di ;restore value to reg DX
XinstB
;***********************************************************
;* ADD IX,SP Flags: S Z - H - P/V N C *
;* . . x x x . 0 ^ *
;***********************************************************
Z_ADxsp:
mov BYTE [FlagN],0
mov di,dx ;save value in reg DX
lahf
and ah,11111110b
mov dh,ah
mov si,[Z80SP]
add [Z80IX],si
lahf
and ah,00000001b
or ah,dh
mov dx,di ;restore value to reg DX
XinstB
;***********************************************************
;* ADD IY,BC Flags: S Z - H - P/V N C *
;* . . x x x . 0 ^ *
;***********************************************************
Z_ADybc:
mov BYTE [FlagN],0
mov di,dx ;save value in reg DX
lahf
and ah,11111110b
mov dh,ah
add [Z80IY],cx
lahf
and ah,00000001b
or ah,dh
mov dx,di ;restore value to reg DX
XinstB
;***********************************************************
;* ADD IY,DE Flags: S Z - H - P/V N C *
;* . . x x x . 0 ^ *
;***********************************************************
Z_ADyde:
mov BYTE [FlagN],0
mov di,cx ;save value in reg CX
lahf
and ah,11111110b
mov ch,ah
add [Z80IY],dx
lahf
and ah,00000001b
or ah,ch
mov cx,di ;restore value to reg CX
XinstB
;***********************************************************
;* ADD IY,IY Flags: S Z - H - P/V N C *
;* . . x x x . 0 ^ *
;***********************************************************
Z_ADyy:
mov BYTE [FlagN],0
mov di,dx ;save value in reg DX
lahf
and ah,11111110b
mov dh,ah
mov si,[Z80IY]
add [Z80IY],si
lahf
and ah,00000001b
or ah,dh
mov dx,di ;restore value to reg DX
XinstB
;***********************************************************
;* ADD IY,SP Flags: S Z - H - P/V N C *
;* . . x x x . 0 ^ *
;***********************************************************
Z_ADysp:
mov BYTE [FlagN],0
mov di,dx ;save value in reg DX
lahf
and ah,11111110b
mov dh,ah
mov si,[Z80SP]
add [Z80IY],si
lahf
and ah,00000001b
or ah,dh
mov dx,di ;restore value to reg DX
XinstB
;***********************************************************
;* ADC HL,BC Flags: S Z - H - P/V N C *
;* ^ ^ x x x V 0 ^ *
;***********************************************************
Z_AChlbc:
mov BYTE [FlagN],0
adc bx,cx
jo achlbc
XinstC
achlbc: XinstD
;***********************************************************
;* ADC HL,DE Flags: S Z - H - P/V N C *
;* ^ ^ x x x V 0 ^ *
;***********************************************************
Z_AChlde:
mov BYTE [FlagN],0
adc bx,dx
jo achlde
XinstC
achlde: XinstD
;***********************************************************
;* ADC HL,HL Flags: S Z - H - P/V N C *
;* ^ ^ x x x V 0 ^ *
;***********************************************************
Z_AChlhl:
mov BYTE [FlagN],0
adc bx,bx
jo achlhl
XinstC
achlhl: XinstD
;***********************************************************
;* ADC HL,SP Flags: S Z - H - P/V N C *
;* ^ ^ x x x V 0 ^ *
;***********************************************************
Z_AChlsp:
mov BYTE [FlagN],0
adc bx,[Z80SP]
jo achlsp
XinstC
achlsp: XinstD
;***********************************************************
;* SBC HL,BC Flags: S Z - H - P/V N C *
;* ^ ^ x x x V 1 ^ *
;***********************************************************
Z_SChlbc:
mov BYTE [FlagN],2
sbb bx,cx
jo schlbc
XinstC
schlbc: XinstD
;***********************************************************
;* SBC HL,DE Flags: S Z - H - P/V N C *
;* ^ ^ x x x V 1 ^ *
;***********************************************************
Z_SChlde:
mov BYTE [FlagN],2
sbb bx,dx
jo schlde
XinstC
schlde: XinstD
;***********************************************************
;* SBC HL,HL Flags: S Z - H - P/V N C *
;* ^ ^ x x x V 1 ^ *
;***********************************************************
Z_SChlhl:
mov BYTE [FlagN],2
sbb bx,bx
jo schlhl
XinstC
schlhl: XinstD
;***********************************************************
;* SBC HL,SP Flags: S Z - H - P/V N C *
;* ^ ^ x x x V 1 ^ *
;***********************************************************
Z_SChlsp:
mov BYTE [FlagN],2
sbb bx,[Z80SP]
jo schlsp
XinstC
schlsp: XinstD
;***********************************************************
;* INC BC Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_INCbc:
lahf
inc cx
XinstB
;***********************************************************
;* INC DE Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_INCde:
lahf
inc dx
XinstB
;***********************************************************
;* INC HL Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_INChl:
lahf
inc bx
XinstB
;***********************************************************
;* INC SP Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_INCsp:
lahf
inc WORD [Z80SP]
XinstB
;***********************************************************
;* INC IX Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_INCx:
lahf
inc WORD [Z80IX]
XinstB
;***********************************************************
;* INC IY Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_INCy:
lahf
inc WORD [Z80IY]
XinstB
;***********************************************************
;* DEC BC Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_DECbc:
lahf
dec cx
XinstB
;***********************************************************
;* DEC DE Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_DECde:
lahf
dec dx
XinstB
;***********************************************************
;* DEC HL Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_DEChl:
lahf
dec bx
XinstB
;***********************************************************
;* DEC SP Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_DECsp:
lahf
dec WORD [Z80SP]
XinstB
;***********************************************************
;* DEC IX Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_DECx:
lahf
dec WORD [Z80IX]
XinstB
;***********************************************************
;* DEC IY Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_DECy:
lahf
dec WORD [Z80IY]
XinstB
end

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,354 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* Call and Return Group *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 10 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Changed 'lea' instructions to 'mov'.
; - Changed all uses of 'Z80' map segment to 'es:Z80'
; - Added 'align=16' to all SEGMENT declarations. (nasm def is align=1)
;
; v1.00 - 28 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
SEGMENT Z80map public align=16
Z80:
SEGMENT .code public align=16
GLOBAL Z_RETN, Z_RETI
GLOBAL Z_RETNZ, Z_RETZ, Z_RET, Z_RETNC, Z_RETC
GLOBAL Z_RETPO, Z_RETPE, Z_RETP, Z_RETM
GLOBAL Z_CALLNZ, Z_CALLZ, Z_CALL, Z_CALLNC, Z_CALLC
GLOBAL Z_CALLPO, Z_CALLPE, Z_CALLP, Z_CALLM
GLOBAL Z_RST0, Z_RST1, Z_RST2, Z_RST3
GLOBAL Z_RST4, Z_RST5, Z_RST6, Z_RST7
; declared in FUNCTION.ASM
EXTERN Nocde0
; declared in INSTHAND.ASM
EXTERN Z80SP
%include "macros.asm"
;***********************************************************
;* CALL NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_CALL:
mov di,[Z80SP]
mov si,bp
lahf
dec di
dec di
inc si
inc si
mov [Z80SP],di
mov word [es:Z80+di],si
mov bp,word [es:Z80+bp]
XinstB
;***********************************************************
;* CALL NZ,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_CALLNZ:
jnz callnz
lahf
inc bp
inc bp
XinstB
callnz: jmp Z_CALL
;***********************************************************
;* CALL Z,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_CALLZ:
jz callz
lahf
inc bp
inc bp
XinstB
callz: jmp Z_CALL
;***********************************************************
;* CALL NC,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_CALLNC:
jnc callnc
lahf
inc bp
inc bp
XinstB
callnc: jmp Z_CALL
;***********************************************************
;* CALL C,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_CALLC:
jc callc
lahf
inc bp
inc bp
XinstB
callc: jmp Z_CALL
;***********************************************************
;* CALL PO,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_CALLPO:
jpo callpo
lahf
inc bp
inc bp
XinstB
callpo: jmp Z_CALL
;***********************************************************
;* CALL PE,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_CALLPE:
jpe callpe
lahf
inc bp
inc bp
XinstB
callpe: jmp Z_CALL
;***********************************************************
;* CALL P,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_CALLP:
jns callp
lahf
inc bp
inc bp
XinstB
callp: jmp Z_CALL
;***********************************************************
;* CALL M,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_CALLM:
js callm
lahf
inc bp
inc bp
XinstB
callm: jmp Z_CALL
;***********************************************************
;* RET Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RET:
mov si,[Z80SP]
mov bp,word [es:Z80+si]
lahf
inc si
inc si
mov [Z80SP],si
XinstB
;***********************************************************
;* RET NZ Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RETNZ:
jnz retnz
XinstA
retnz: jmp Z_RET
;***********************************************************
;* RET Z Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RETZ:
jz retz
XinstA
retz: jmp Z_RET
;***********************************************************
;* RET NC Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RETNC:
jnc retnc
XinstA
retnc: jmp Z_RET
;***********************************************************
;* RET C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RETC:
jc retc
XinstA
retc: jmp Z_RET
;***********************************************************
;* RET PO Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RETPO:
jpo retpo
XinstA
retpo: jmp Z_RET
;***********************************************************
;* RET PE Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RETPE:
jpe retpe
XinstA
retpe: jmp Z_RET
;***********************************************************
;* RET P Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RETP:
jns retp
XinstA
retp: jmp Z_RET
;***********************************************************
;* RET M Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RETM:
js retm
XinstA
retm: jmp Z_RET
;***********************************************************
;* RETI Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RETI:
mov si,reti_
jmp NEAR Nocde0
reti_: db 'RETI$'
;***********************************************************
;* RETN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RETN:
mov si,retn_
jmp NEAR Nocde0
retn_: db 'RETN$'
;***********************************************************
;* RST 0 Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RST0:
mov si,0000h
restor: mov di,[Z80SP]
lahf
dec di
dec di
mov [Z80SP],di
mov word [es:Z80+di],bp
mov bp,si
XinstB
;***********************************************************
;* RST 1 Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RST1:
mov si,0008h
jmp restor
;***********************************************************
;* RST 2 Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RST2:
mov si,0010h
jmp restor
;***********************************************************
;* RST 3 Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RST3:
mov si,0018h
jmp restor
;***********************************************************
;* RST 4 Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RST4:
mov si,0020h
jmp restor
;***********************************************************
;* RST 5 Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RST5:
mov si,0028h
jmp restor
;***********************************************************
;* RST 6 Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RST6:
mov si,0030h
jmp restor
;***********************************************************
;* RST 7 Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RST7:
mov si,0038h
jmp restor
end

View File

@@ -0,0 +1,208 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* General Purpose Arithmetic and CPU Control Groups *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 25 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Changed 'lea' instructions to 'mov'.
; - Added 'align=16' to all SEGMENT declarations. (nasm def is align=1)
; - Fixed DAA instruction to give the correct half carry flag result.
; - The CCF instruction (Z_CCF) code required changes as the Zilog data book
; was incorrect concerning the 'H' flag.
;
; v1.00 - 28 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
SEGMENT Z80map public align=16
Z80:
SEGMENT .code public align=16
GLOBAL Z_IM0, Z_IM1, Z_IM2, Z_DI, Z_EI, Z_HALT
GLOBAL Z_DAA, Z_CPL, Z_NEG, Z_SCF, Z_CCF, Z_NOP
; declared in FUNCTION.ASM
EXTERN Nocde0, Nocde1
; declared in INSTHAND.ASM
EXTERN IFF, FlagN
%include "macros.asm"
;***********************************************************
;* DAA Flags: S Z - H - P/V N C *
;* ^ ^ x ^ x P . ^ *
;***********************************************************
Z_DAA:
mov [temp1],al ;keep track of bit 4
lahf
mov si,ax ;save ah (orig flags)
and ah,00000001b ;save the carry flag
cmp al,99h
jbe daa0 ;if below or equal
mov ah,00000001b ;set the carry flag
daa0: mov [temp2],ah
mov ax,si ;get back ah (orig flags)
cmp BYTE [FlagN],2
jz daa1
sahf
daa
lahf
and ah,11101110b ;clear both carry flags
xor [temp1],al ;if bit 4 changed then H=1
and BYTE [temp1],00010000b ;keep the half carry flag
or ah,BYTE [temp1] ;add in half carry flag
or ah,BYTE [temp2] ;add in carry flag
XinstB
daa1: sahf
das
lahf
and ah,11101110b ;clear both carry flags
xor [temp1],al ;if bit 4 changed then H=1
and BYTE [temp1],00010000b ;keep the half carry flag
or ah,BYTE [temp1] ;add in half carry flag
or ah,BYTE [temp2] ;add in carry flag
XinstB
temp1 resb 1
temp2 resb 1
;***********************************************************
;* CPL Flags: S Z - H - P/V N C *
;* . . x 1 x . 1 . *
;***********************************************************
Z_CPL:
lahf
not al
or ah,00010000b ;set the half carry flag
mov BYTE [FlagN],2
XinstB
;***********************************************************
;* NEG Flags: S Z - H - P/V N C *
;* ^ ^ x ^ x V 1 ^ *
;***********************************************************
Z_NEG:
neg al
mov BYTE [FlagN],2
jo neg_
XinstC
neg_: XinstD
;***********************************************************
;* CCF Flags: S Z - H - P/V N C *
;* . . x ^ x . 0 ^ *
;***********************************************************
Z_CCF:
cmc
mov BYTE [FlagN],0
lahf
jc ccf_
or ah,00010000b ;set the half carry flag
XinstB
ccf_: and ah,11101111b ;clear the half carry flag
XinstB
;***********************************************************
;* SCF Flags: S Z - H - P/V N C *
;* . . x 0 x . 0 1 *
;***********************************************************
Z_SCF:
stc
mov BYTE [FlagN],0
lahf
and ah,11101111b ;clear the half carry flag
XinstB
;***********************************************************
;* NOP Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_NOP:
XinstA
;***********************************************************
;* HALT Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_HALT:
mov si,halt
jmp NEAR Nocde1
halt: db 'HALT$'
;***********************************************************
;* DI Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_DI:
mov BYTE [IFF],0
XinstA
;***********************************************************
;* EI Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_EI:
mov BYTE [IFF],4
XinstA
;***********************************************************
;* IM 0 Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_IM0:
mov si,im0
jmp NEAR Nocde0
im0: db 'IM 0$'
;***********************************************************
;* IM 1 Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_IM1:
mov si,im1
jmp NEAR Nocde0
im1: db 'IM 1$'
;***********************************************************
;* IM 2 Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_IM2:
mov si,im2
jmp NEAR Nocde0
im2: db 'IM 2$'
end

View File

@@ -0,0 +1,277 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* Exchange, Block Transfer, Block Search Groups *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 10 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Changed all uses of 'Z80' map segment to 'es:Z80'
; - Added 'align=16' to all SEGMENT declarations. (nasm def is align=1)
;
; v1.00 - 29 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
SEGMENT Z80map public align=16
Z80:
SEGMENT .code public align=16
GLOBAL Z_EXafaf, Z_EXX, Z_EXsphl, Z_EXdehl, Z_EXspx, Z_EXspy
GLOBAL Z_CPI, Z_CPD, Z_CPIR, Z_CPDR
GLOBAL Z_LDI, Z_LDD, Z_LDIR, Z_LDDR
; declared in INSTHAND.ASM
EXTERN Z80SP, Z80IX, Z80IY
EXTERN Z80AF, Z80BC, Z80DE, Z80HL
EXTERN FlagN, FlagNx
%include "macros.asm"
tempb1 resb 1
;***********************************************************
;* EX DE,HL Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_EXdehl:
xchg dx,bx
XinstA
;***********************************************************
;* EXX AF,AF' Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_EXafaf:
mov ah,[FlagN]
xchg ah,[FlagNx]
mov [FlagN],ah
lahf
xchg ax,[Z80AF]
XinstB
;***********************************************************
;* EXX Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_EXX:
xchg cx,[Z80BC]
xchg dx,[Z80DE]
xchg bx,[Z80HL]
XinstA
;***********************************************************
;* EX (SP),HL Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_EXsphl:
mov di,[Z80SP]
xchg bx,word [es:Z80+di]
XinstA
;***********************************************************
;* EX (SP),IX Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_EXspx:
mov di,[Z80SP]
mov si,[Z80IX]
xchg si,word [es:Z80+di]
mov [Z80IX],si
XinstA
;***********************************************************
;* EX (SP),IY Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_EXspy:
mov di,[Z80SP]
mov si,[Z80IY]
xchg si,word [es:Z80+di]
mov [Z80IY],si
XinstA
;***********************************************************
;* LDI Flags: S Z - H - P/V N C *
;* . . x 0 x ^ 0 . *
;***********************************************************
Z_LDI:
mov BYTE [FlagN],0
mov ah,[es:Z80+bx] ;source in HL
mov di,dx ;destination in DE
mov BYTE [es:Z80+di],ah
lahf
inc bx
inc dx
dec cx
and ah,11101011b ;lose half carry and parity flag
jcxz ldi
or ah,00000100b ;set parity flag (BC <> 0)
ldi: XinstB
;***********************************************************
;* LDIR Flags: S Z - H - P/V N C *
;* . . x 0 x 0 0 . *
;***********************************************************
Z_LDIR:
lahf
mov si,bx ;source in HL
mov di,dx ;destination in DE
push ds
push es
pop ds
cld
rep movsb ;move memory
pop ds
mov bx,si
mov dx,di
and ah,11101011b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* LDD Flags: S Z - H - P/V N C *
;* . . x 0 x ^ 0 . *
;***********************************************************
Z_LDD:
mov BYTE [FlagN],0
mov ah,[es:Z80+bx] ;source in HL
mov di,dx ;destination in DE
mov BYTE [es:Z80+di],ah
lahf
dec bx
dec dx
dec cx
and ah,11101011b ;lose half carry and parity flag
jcxz ldd
or ah,00000100b ;set parity flag (BC <> 0)
ldd: XinstB
;***********************************************************
;* LDDR Flags: S Z - H - P/V N C *
;* . . x 0 x 0 0 . *
;***********************************************************
Z_LDDR:
lahf
mov si,bx ;source in HL
mov di,dx ;destination in DE
push ds
push es
pop ds
std
rep movsb ;move memory
pop ds
mov bx,si
mov dx,di
and ah,11101011b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* CPI Flags: S Z - H - P/V N C *
;* ^ ^ x ^ x ^ 1 . *
;***********************************************************
Z_CPI:
lahf
and ah,00000001b ;save the carry flag
mov [tempb1],ah
mov BYTE [FlagN],2
cmp al,[es:Z80+bx] ;compare A=(HL)
lahf
inc bx
dec cx
and ah,11111010b ;lose the carry and parity flag
or ah,[tempb1] ;and replace with old carry flag
jcxz cpi
or ah,00000100b ;set parity flag (BC <> 0)
cpi: XinstB
;***********************************************************
;* CPIR Flags: S Z - H - P/V N C *
;* ^ ^ x ^ x ^ 1 . *
;***********************************************************
Z_CPIR:
lahf
and ah,00000001b ;save the carry flag
mov [tempb1],ah
mov BYTE [FlagN],2
mov di,bx ;Z80 HL to DI reg
cld
repne scasb ;repeat until CX=0 or A=(HL)
mov bx,di ;DI reg TO Z80 HL
lahf
and ah,11111010b ;lose the carry and parity flag
or ah,[tempb1] ;and replace with old carry flag
jcxz cpir
or ah,00000100b ;set parity flag (BC <> 0)
cpir: XinstB
;***********************************************************
;* CPD Flags: S Z - H - P/V N C *
;* ^ ^ x ^ x ^ 1 . *
;***********************************************************
Z_CPD:
lahf
and ah,00000001b ;save the carry flag
mov [tempb1],ah
mov BYTE [FlagN],2
cmp al,[es:Z80+bx] ;compare A=(HL)
lahf
dec bx
dec cx
and ah,11111010b ;lose the carry and parity flag
or ah,[tempb1] ;and replace with old carry flag
jcxz cpd
or ah,00000100b ;set parity flag (BC <> 0)
cpd: XinstB
;***********************************************************
;* CPDR Flags: S Z - H - P/V N C *
;* ^ ^ x ^ x ^ 1 . *
;***********************************************************
Z_CPDR:
lahf
and ah,00000001b ;save the carry flag
mov [tempb1],ah
mov BYTE [FlagN],2
mov di,bx ;Z80 HL to DI reg
std
repne scasb ;repeat until CX=0 or A=(HL)
mov bx,di ;DI reg TO Z80 HL
lahf
and ah,11111010b ;lose the carry and parity flag
or ah,[tempb1] ;and replace with old carry flag
jcxz cpdr
or ah,00000100b ;set parity flag (BC <> 0)
cpdr: XinstB
end

View File

@@ -0,0 +1,679 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* General function interface support for Z80 system code *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 25 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Changed 'lea' instructions to 'mov'.
; - Changed all uses of 'Z80' map segment to 'es:Z80'
; - Added 'align=16' to all SEGMENT declarations. (nasm def is align=1)
; - Added code to display 4 opcodes at the PC when a trap occurs.
;
; v1.00 - 28 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
SEGMENT Z80map public align=16
Z80:
SEGMENT .code public align=16
GLOBAL criter
GLOBAL fboot, SysErr
GLOBAL BufCnt, BootDr
GLOBAL fnc___, trp0__, trp1__
GLOBAL Nocde0, Nocde1, ReqAct, GtZseg
GLOBAL GetByt, SetByt
GLOBAL GtBoot
GLOBAL intfnc
GLOBAL blkcnt, blkget, blkput, blkfil
GLOBAL prmsta, prmget, vidsta, vidset
GLOBAL usrbyt, failed, rstz80, extemu
; declared in MAIN.ASM
EXTERN Z80res, Z80opc, Z80ext
EXTERN prmflg, vidoff, prmbuf
EXTERN BufSeg
; declared in WINDOW.ASM
EXTERN OpnWnd, ClsWnd, PrnStr
EXTERN PrnByt, PrnHex, GetAct
; declared in TABLE.ASM
EXTERN T0, Tx
; declared in HARDWARE.ASM
EXTERN Z80seg, Z80dma, cpycom
EXTERN sveoff, sveseg, sveamt, reqcpy
%include "macros.asm"
;===============================================================================
; DOS critical error handler
;===============================================================================
criter: sti ;turn interrupts back on
push ds
push es
push bx
push cx
push dx
push si
push di
push bp
push cs
pop ds ;address local data
mov dh,8 ;window Y start
mov dl,17 ;window X start
mov ch,16 ;window Y finish
mov cl,62 ;window X finish
call NEAR OpnWnd
add al,'A' ;drive letter if disk error
mov [ErrDrv],al ;place in error message
test ah,080h
mov dx,ErrMsB ;Type: disk error on drive X message
jz FndTyp
mov es,bp
test word [es:si+4],8000h
mov dx,ErrMsC ;Type: charater device message
jnz FndTyp
mov dx,ErrMsD ;Type: block device message
FndTyp: mov si,ErrMsA ;dos critical error message
call NEAR PrnStr
mov si,dx
call NEAR PrnStr ;display the error type
mov si,ErrMsE
call NEAR PrnStr ;Error: message
mov si,ErrMXX
mov bx,di
cmp bl,010h ;is error code in range ?
jnc shwerr
xor bh,bh
add bx,bx
mov si,[ErrTbl+bx]
shwerr: call NEAR PrnStr
mov si,ErrMsF ;Code: message
call NEAR PrnStr
mov bx,di
mov al,bl
call NEAR PrnHex ;print error number in hex
mov si,ErrMsG ;cr, lf, lf
call NEAR PrnStr
mov bx,ErrKey
test ah,010h ;retry response allowed ?
jz noretr
mov byte [bx],'R'
inc bx
mov si,ErrMsH ;retry message
call NEAR PrnStr
noretr: test ah,020h ;Ignore response allowed ?
jz noignr
mov byte [bx],'I'
inc bx
mov si,ErrMsI ;ignore message
call NEAR PrnStr
noignr: test ah,008h ;fail response allowed ?
jz nofail
mov byte [bx],'F'
inc bx
mov si,ErrMsJ ;fail message
call NEAR PrnStr
nofail: mov byte [bx],'$'
mov si,ErrMsK ;Action ? message
call NEAR PrnStr
mov si,ErrKey
call NEAR GetAct
cmp al,'R' ;retry action requested ?
mov ah,1 ;retry code
jz critex
cmp al,'I' ;ignore action requested ?
mov ah,0
jz critex
mov ah,3 ;fail code
critex: mov al,ah
call NEAR ClsWnd
pop bp
pop di
pop si
pop dx
pop cx
pop bx
pop es
pop ds
iret
ErrKey db '$$$$'
ErrTbl dw ErrM00, ErrM01, ErrM02, ErrM03, ErrM04, ErrM05, ErrM06, ErrM07
dw ErrM08, ErrM09, ErrM0A, ErrM0B, ErrM0C, ErrM0D, ErrM0E, ErrM0F
ErrMsA db ' DOS CRITICAL ERROR', 0dh, 0ah, '$'
ErrMsB db ' Type: Disk error on drive '
ErrDrv db ' ', 0dh, 0ah, '$'
ErrMsC db ' Type: Character device', 0dh, 0ah, '$'
ErrMsD db ' Type: Block device', 0dh, 0ah, '$'
ErrMsE db 'Error: $'
ErrMsF db ' Code: $'
ErrMsG db 0dh, 0ah, 0ah, '$'
ErrMsH db '[R]etry $'
ErrMsI db '[I]gnore $'
ErrMsJ db '[F]ail$'
ErrMsK db 0dh, 0ah, 'Action ?: $'
ErrM00 db 'Write-protect error', 0dh, 0ah, '$'
ErrM01 db 'Invalid drive number', 0dh, 0ah, '$'
ErrM02 db 'Drive not ready', 0dh, 0ah, '$'
ErrM03 db 'Unknown command requested', 0dh, 0ah, '$'
ErrM04 db 'Data error (CRC)', 0dh, 0ah, '$'
ErrM05 db 'Bad request structure length', 0dh, 0ah, '$'
ErrM06 db 'Seek error', 0dh, 0ah, '$'
ErrM07 db 'Unknown disk format', 0dh, 0ah, '$'
ErrM08 db 'Sector not found', 0dh, 0ah, '$'
ErrM09 db 'Printer out of paper', 0dh, 0ah, '$'
ErrM0A db 'Write fault', 0dh, 0ah, '$'
ErrM0B db 'Read fault', 0dh, 0ah, '$'
ErrM0C db 'General, non specific error', 0dh, 0ah, '$'
ErrM0D db 'UNDOCUMENTED ERROR 0D', 0dh, 0ah, '$'
ErrM0E db 'UNDOCUMENTED ERROR 0E', 0dh, 0ah, '$'
ErrM0F db 'Invalid disk change', 0dh, 0ah, '$'
ErrMXX db 'UNKNOWN ERROR', 0dh, 0ah, '$'
;===============================================================================
; Reset Z80 emulator
;===============================================================================
rstz80: pop ax ;discard near return address
pop ax ;discard Z80 reg PC
pop ax ;discard Z80 reg HL
pop ax ;discard Z80 reg DE
pop ax ;discard Z80 reg BC
jmp NEAR Z80res
;===============================================================================
; Exit from Z80 emulator to DOS
;===============================================================================
extemu: pop ax ;discard near return address
pop ax ;discard Z80 reg PC
pop ax ;discard Z80 reg HL
pop ax ;discard Z80 reg DE
pop ax ;discard Z80 reg BC
jmp NEAR Z80ext
;===============================================================================
; Failure to boot Z80 system disk
;===============================================================================
failed: pop ax ;discard near return address
pop ax ;discard Z80 reg PC
pop ax ;discard Z80 reg HL
pop ax ;discard Z80 reg DE
pop ax ;discard Z80 reg BC
fboot: mov dh,9 ;window Y start
mov dl,23 ;window X start
mov ch,14 ;window Y finish
mov cl,57 ;window X finish
call NEAR OpnWnd
mov si,BtfMsg
call NEAR PrnStr
jmp ActRE
;===============================================================================
; 1st byte of boot sector not $C3 (Z80 jump)
;===============================================================================
SysErr: mov dh,9 ;window Y start
mov dl,18 ;window X start
mov ch,15 ;window Y finish
mov cl,61 ;window X finish
call NEAR OpnWnd
mov si,SysMsg
call NEAR PrnStr
jmp ActRE
;===============================================================================
; Unsupported OUT (Fn),A code function
;===============================================================================
fnc___: pop ax ;discard near return address
pop ax ;discard Z80 reg PC
pop ax ;discard Z80 reg HL
pop ax ;discard Z80 reg DE
pop ax ;discard Z80 reg BC
dec bp
dec bp ;address of OUT (Fn),A code
mov dh,9 ;window Y start
mov dl,21 ;window X start
mov ch,15 ;window Y finish
mov cl,58 ;window X finish
call NEAR OpnWnd
mov si,FncMsg
jmp ShwPC
;===============================================================================
; Illegal OUT (Fn),A / 8086 INT function call
;===============================================================================
IntErr: pop ax ;discard near return address
pop ax ;discard Z80 reg PC
pop ax ;discard Z80 reg HL
pop ax ;discard Z80 reg DE
pop ax ;discard Z80 reg BC
dec bp
dec bp ;address of OUT (Fn),A code
mov dh,9 ;window Y start
mov dl,16 ;window X start
mov ch,15 ;window Y finish
mov cl,62 ;window X finish
call NEAR OpnWnd
mov si,IntMsg
jmp ShwPC
;===============================================================================
; Trap undocumented Z80 opcodes
;===============================================================================
trp0__: dec bp
dec bp
trp1__: dec bp
dec bp
mov dh,9 ;window Y start
mov dl,23 ;window X start
mov ch,15 ;window Y finish
mov cl,56 ;window X finish
call NEAR OpnWnd
mov si,OpcMsg
jmp ShwPC
;===============================================================================
; Trap non emulated Z80 opcodes
;===============================================================================
Nocde0: dec bp
Nocde1: dec bp
mov dh,9 ;window Y start
mov dl,19 ;window X start
mov ch,16 ;window Y finish
mov cl,59 ;window X finish
call NEAR OpnWnd
push si
mov si,CdeMsg
call NEAR PrnStr
pop si
;
ShwPC: call NEAR PrnStr
mov si,PCaddr
call NEAR PrnStr
mov ax,bp
xchg ah,al
call NEAR PrnHex
xchg ah,al
call NEAR PrnHex
; display the 4 opcodes at the PC location
mov si,OpcMs0
call NEAR PrnStr
mov al,[es:Z80+bp+0]
call NEAR PrnHex
mov si,SpcMsg
call NEAR PrnStr
mov al,[es:Z80+bp+1]
call NEAR PrnHex
mov si,SpcMsg
call NEAR PrnStr
mov al,[es:Z80+bp+2]
call NEAR PrnHex
mov si,SpcMsg
call NEAR PrnStr
mov al,[es:Z80+bp+3]
call NEAR PrnHex
mov si,OpcMs1
call NEAR PrnStr
ActRE: mov si,REsels
call NEAR PrnStr
mov si,KeyRE
call NEAR GetAct
call NEAR ClsWnd
cmp al,'R'
jz z80rs0
jmp NEAR Z80ext
z80rs0: jmp NEAR Z80res
BtfMsg: db 'Failure loading Z80 system code$'
SysMsg: db 'Disk in drive is not a Z80 system disk', 0dh, 0ah
db 'Requires C3 hex (Z80 Jump) as 1st byte$'
OpcMsg: db 'Undocumented Z80 opcode$'
FncMsg: db 'OUT (Fn),A Function Not Supported$'
IntMsg: db 'Illegal OUT (Fn),A / 8086 INT function call$'
CdeMsg: db 'No code emulation for this Z80 opcode', 0dh, 0ah
db 'Mnemonic: $'
PCaddr: db 0dh, 0ah
db ' at PC: $'
OpcMs0: db ' ($'
OpcMs1: db ')$'
SpcMsg: db ' $'
REsels: db 0dh, 0ah, 0ah
db '[R]eset Z80 [E]xit to DOS', 0dh, 0ah
db 'Select ?: $'
KeyRE: db 'RE$'
;===============================================================================
; User Interrupt (CTRL+ALT+I)
;===============================================================================
ReqAct: pushf
push ax
push bx
push cx
push dx
push es
push ds
pop es
mov si,Tx
mov di,T0
mov cx,512
cld
rep movsb
pop es
dec bp ;point to Z80 current PC
mov dh,9 ;window Y start
mov dl,19 ;window X start
mov ch,15 ;window Y finish
mov cl,60 ;window X finish
call NEAR OpnWnd
mov si,ExeMsg
call NEAR PrnStr
mov ax,bp
xchg ah,al
call NEAR PrnHex
xchg ah,al
call NEAR PrnHex
mov si,RECmsg
call NEAR PrnStr
mov si,KeyREC
call NEAR GetAct
call NEAR ClsWnd
cmp al,'R'
jz z80rs1
cmp al,'C'
jz conact
pop dx
pop cx
pop bx
pop ax
popf
jmp NEAR Z80ext
z80rs1: pop dx
pop cx
pop bx
pop ax
popf
jmp NEAR Z80res
conact: pop dx
pop cx
pop bx
pop ax
popf
jmp NEAR Z80opc
ExeMsg: db 'Execution Interrupted (Ctrl + Alt + I)', 0dh, 0ah
db 'Current PC: $'
RECmsg: db 0dh, 0ah, 0ah
db '[R]eset Z80 [E]xit to DOS [C]ontinue', 0dh, 0ah
db 'Select ?: $'
KeyREC: db 'REC$'
;===============================================================================
; Various other functions
;===============================================================================
prmsta: mov al,[prmflg]
retn
prmget: mov word [es:Z80+bx],ds
mov ax,prmbuf
mov word [es:Z80+bx+2],ax
retn
vidsta: mov al,[vidoff]
retn
vidset: mov [vidoff],al
retn
;
usrdta times 32 db 0
usrbyt: cmp bx,020h ;is user byte in range
jnc usrext
or cl,cl
jz usrget
mov BYTE [usrdta+bx],al ;set user byte
retn
usrget: mov al,[usrdta+bx] ;get user byte
usrext: retn
;
BootDr db 0
GtBoot: mov al,[BootDr]
retn
;
;===============================================================================
; Block memory routines:
;
; blkcnt:- Get count of blocks available (1 block=16384 bytes)
; Return: A(AL)=number of blocks
; blkget:- Get 128 bytes from block (1 record=128 bytes) from
; the current DMA bank. (see bnkdma function)
; Pass: C(CL)=block number
; D(DH)=starting record number
; E(DL)=number of records
; HL(BX)=Z80 destination address
; blkput:- Put 128 bytes in block (1 record=128 bytes) for
; the current DMA bank. (see bnkdma function)
; Pass: C(CL)=block number
; D(DH)=starting record number
; E(DL)=number of records
; HL(BX)=Z80 source address
; blkfil:- Fill 128 bytes in block (1 record=128 bytes) for
; the current DMA bank. (see bnkdma function)
; Pass: A(AL)=fill value
; C(CL)=block number
; D(DH)=starting record number
; E(DL)=number of records
;===============================================================================
; Get count of blocks available (1 block=16384 bytes)
BufCnt db 0
blkcnt: mov al,[BufCnt]
retn
; Get 128 bytes from block (1 record=128 bytes) from the current DMA bank.
blkget: mov di,bx ;destination address in Z80 reg HL
call blkprm
jz blkg
retn
blkg: mov si,cx
cld ;move upwards
nxtget: mov BYTE [reqcpy],0ffh ;copy common required
mov cx,128
mov [sveamt],cx
mov [sveoff],di
push ds
push es
mov es,[Z80dma] ;bank #0, #1 DMA segment address
mov [sveseg],es
mov ds,[BufSeg+bx]
rep movsb
pop es
pop ds
call NEAR cpycom ;copy common if needed
dec dl
jnz nxtget
xor al,al
retn
; Put 128 bytes in block (1 record=128 bytes) for the current DMA bank.
blkput: mov si,bx ;source address in Z80 reg HL
call blkprm
jz blkp
retn
blkp: mov di,cx
push ds
push es
mov es,[BufSeg+bx]
mov ds,[Z80dma] ;bank #0, #1 DMA segment address
cld ;move upwards
nxtput: mov cx,128
rep movsb
dec dl
jnz nxtput
pop es
pop ds
xor al,al
retn
; Fill 128 bytes in block (1 record=128 bytes) for the current DMA bank.
blkfil: mov si,ax
call blkprm
jz blkf
retn
blkf: mov ax,si
mov di,cx
cld ;fill upwards
push es
mov es,[BufSeg+bx]
nxtfil: mov cx,128
rep stosb
dec dl
jnz nxtfil
pop es
xor al,al
retn
blkprm: cmp cl,[BufCnt] ;block # in Z80 reg C
jnc blkerr
cmp dh,128
jnc blkerr
xor bh,bh
mov bl,cl
shl bl,1
mov ch,dh
xor cl,cl
shr cx,1
xor al,al
retn
blkerr: xor al,al
inc al
retn
;===============================================================================
; Interrupt services:
;
; GtZseg:- Return Z80 map segment address
; Pass: HL(BX)=Z80 address to place result
; intfnc:- Call a ROM BIOS/DOS Interrupt service
; Pass: BC(CX)=0AA55h
; DE(DX)=055AAh
; HL(BX)=base address of register table
; A(AL)=Interrupt
; GetByt:- Get byte from memory
; Pass: DE(DX)=segment
; HL(BX)=offset
; Return: A(AL)=byte
; SetByt:- Set byte in memory
; Pass: DE(DX)=segment
; HL(BX)=offset
; A(AL)=byte
;===============================================================================
; Call a ROM BIOS/DOS Interrupt service
intfnc: cmp cx,0aa55h ;safety gaurd check
jz Pass1
jmp IntErr
Pass1: cmp dx,055aah ;safety gaurd check
jz Pass2
jmp IntErr
Pass2: mov byte [cs:setint+1],al
mov bp,bx ;base address of register table
mov [SaveBP],bp
push word [es:Z80+bp+000h] ;AX
push word [es:Z80+bp+002h] ;BX
push word [es:Z80+bp+004h] ;CX
push word [es:Z80+bp+006h] ;DX
push word [es:Z80+bp+008h] ;BP
push word [es:Z80+bp+00ah] ;SI
push word [es:Z80+bp+00ch] ;DI
push word [es:Z80+bp+00eh] ;DS
push word [es:Z80+bp+010h] ;ES
pop es
pop ds
pop di
pop si
pop bp
pop dx
pop cx
pop bx
pop ax
setint: int 0 ;interrupt placed here
push es
push ds
push di
push si
push bp
push dx
push cx
push bx
push ax
mov ax,cs
mov ds,ax
mov ax,[Z80seg]
mov es,ax
mov bp,[SaveBP]
pop word [es:Z80+bp+000h] ;AX
pop word [es:Z80+bp+002h] ;BX
pop word [es:Z80+bp+004h] ;CX
pop word [es:Z80+bp+006h] ;DX
pop word [es:Z80+bp+008h] ;BP
pop word [es:Z80+bp+00ah] ;SI
pop word [es:Z80+bp+00ch] ;DI
pop word [es:Z80+bp+00eh] ;DS
pop word [es:Z80+bp+010h] ;ES
pushf
pop word [es:Z80+bp+012h] ;FLAGS
retn
SaveBP resw 1
; Return Z80 map segment address
GtZseg: mov word [es:Z80+bx],es ;bank #0 or Bank #1 segment
retn
; Get byte from memory
GetByt: push ds
mov ds,dx
mov al,[bx]
pop ds
retn
; Set byte in memory
SetByt: push ds
mov ds,dx
mov [bx],al
pop ds
retn
end

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,178 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* Instruction Handler for Extended Opcodes *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 10 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Changed all uses of 'Z80' map segment to 'es:Z80'
; - Added 'align=16' to all SEGMENT declarations. (nasm def is align=1)
;
; v1.00 - 28 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
SEGMENT Z80map public align=16
Z80:
SEGMENT .code public align=16
GLOBAL Z_8086, CBxops, CByops, IXops, IYops, EDops, CBops
GLOBAL FlagX, FlagN, FlagNx, IFF
GLOBAL Z80I, Z80R, Z80SP, Z80IX, Z80IY, Z80AF, Z80BC, Z80DE, Z80HL
; declared in TABLE.ASM
EXTERN T0, T1, T2, T3
EXTERN T4, T5, T6, T7
%include "macros.asm"
svewrd resw 1 ;temporary word storage
FlagX resb 1 ;saves flag bits 5 and 3
FlagN resb 1 ;Emulates the Z80 N flag (bit 1)
FlagNx resb 1 ;
IFF resb 1 ;Z80 Interrupt Flip Flop
Z80I resb 1 ;Z80 interrupt register
Z80R resb 1 ;Z80 refresh register
Z80SP resw 1 ;Z80 stack pointer storage
Z80IX resw 1 ;Z80 IX index register storage
Z80IY resw 1 ;Z80 IY index register storage
Z80AF resw 1 ;Z80 2nd AF register storage
Z80BC resw 1 ;Z80 2nd BC register storage
Z80DE resw 1 ;Z80 2nd DE register storage
Z80HL resw 1 ;Z80 2nd HL register storage
; High level interface functions accessed with OUT (FncNmb),A
Z_8086: mov si,ax ;save Z80 reg A
xor ah,ah
mov al,[es:Z80+bp] ;8086 code function number
mov di,ax
shl di,1 ;offset into function table
inc bp ;next Z80 PC
mov ax,si ;restore Z80 reg A
push cx ;save Z80 reg BC
push dx ;save Z80 reg DE
push bx ;save Z80 reg HL
push bp ;save Z80 reg PC
call WORD [T7+di] ;call 8086 code function
pop bp ;restore Z80 reg PC
pop bx ;restore Z80 reg HL
pop dx ;restore Z80 reg DE
pop cx ;restore Z80 reg BC
or al,al ;set/res Z80 zero flag
XinstA
; $CB IX opcode of Z80 instruction
CBxops: lahf ;get Z80 reg F
mov si,ax ;save Z80 regs A and F
mov al,[es:Z80+bp] ;get IX offset
inc bp
cbw
add ax,[Z80IX]
mov [svewrd],ax ;save IX + signed offset
xor ah,ah
mov al,[es:Z80+bp] ;get Z80 opcode
inc bp ;next Z80 PC
mov di,ax
shl di,1
mov ax,si ;restore Z80 reg A and F
sahf ;set Z80 reg F
mov si,[svewrd]
jmp WORD [T6+di]
; $CB IY opcode of Z80 instruction
CByops: lahf ;get Z80 reg F
mov si,ax ;save Z80 regs A and F
mov al,[es:Z80+bp] ;get IY offset
inc bp
cbw
add ax,[Z80IY]
mov [svewrd],ax ;save IY + signed offset
xor ah,ah
mov al,[es:Z80+bp] ;get Z80 opcode
inc bp ;next Z80 PC
mov di,ax
shl di,1
mov ax,si ;restore Z80 reg A and F
sahf ;set Z80 reg F
mov si,[svewrd]
jmp WORD [T5+di]
; IX opcode of Z80 instruction
IXops: lahf ;get Z80 reg F
mov si,ax ;save Z80 regs A and F
xor ah,ah
mov al,[es:Z80+bp] ;get Z80 opcode
mov di,ax
shl di,1
inc bp ;next Z80 PC
mov ax,si ;restore Z80 reg A and F
sahf ;set Z80 reg F
jmp WORD [T4+di]
; IY opcode of Z80 instruction
IYops: lahf ;get Z80 reg F
mov si,ax ;save Z80 regs A and F
xor ah,ah
mov al,[es:Z80+bp] ;get Z80 opcode
mov di,ax
shl di,1
inc bp ;next Z80 PC
mov ax,si ;restore Z80 reg A and F
sahf ;set Z80 reg F
jmp WORD [T3+di]
; $ED opcode of Z80 instruction
EDops: lahf ;get Z80 reg F
mov si,ax ;save Z80 regs A and F
xor ah,ah
mov al,[es:Z80+bp] ;get Z80 opcode
mov di,ax
shl di,1
inc bp ;next Z80 PC
mov ax,si ;restore Z80 reg A and F
sahf ;set Z80 reg F
jmp WORD [T2+di]
; $CB opcode of Z80 instruction
CBops: lahf ;get Z80 reg F
mov si,ax ;save Z80 regs A and F
xor ah,ah
mov al,[es:Z80+bp] ;get Z80 opcode
mov di,ax
shl di,1
inc bp ;next Z80 PC
mov ax,si ;restore Z80 reg A and F
sahf ;set Z80 reg F
jmp WORD [T1+di]
end

View File

@@ -0,0 +1,281 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* Input and Output Group *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 10 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Changed 'lea' instructions to 'mov'.
; - Added 'align=16' to all SEGMENT declarations. (nasm def is align=1)
;
; v1.00 - 29 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
SEGMENT .code public align=16
GLOBAL Z_INan
GLOBAL Z_INbc, Z_INcc, Z_INdc, Z_INec
GLOBAL Z_INhc, Z_INlc, Z_INfc, Z_INac
GLOBAL Z_OUTcb, Z_OUTcc, Z_OUTcd, Z_OUTce
GLOBAL Z_OUTch, Z_OUTcl, Z_OUTca
GLOBAL Z_INI, Z_INIR, Z_IND, Z_INDR
GLOBAL Z_OUTI, Z_OTIR, Z_OUTD, Z_OTDR
; declared in FUNCTION.ASM
EXTERN Nocde0, Nocde1
%include "macros.asm"
;***********************************************************
;* IN B,(C) Flags: S Z - H - P/V N C *
;* ^ ^ x ^ x P 0 . *
;***********************************************************
Z_INbc:
mov si,inbc
jmp NEAR Nocde0
inbc: db 'IN B,(C)$'
;***********************************************************
;* IN C,(C) Flags: S Z - H - P/V N C *
;* ^ ^ x ^ x P 0 . *
;***********************************************************
Z_INcc:
mov si,incc_
jmp NEAR Nocde0
incc_: db 'IN C,(C)$'
;***********************************************************
;* IN D,(C) Flags: S Z - H - P/V N C *
;* ^ ^ x ^ x P 0 . *
;***********************************************************
Z_INdc:
mov si,indc
jmp NEAR Nocde0
indc: db 'IN D,(C)$'
;***********************************************************
;* IN E,(C) Flags: S Z - H - P/V N C *
;* ^ ^ x ^ x P 0 . *
;***********************************************************
Z_INec:
mov si,inec
jmp NEAR Nocde0
inec: db 'IN E,(C)$'
;***********************************************************
;* IN H,(C) Flags: S Z - H - P/V N C *
;* ^ ^ x ^ x P 0 . *
;***********************************************************
Z_INhc:
mov si,inhc
jmp NEAR Nocde0
inhc: db 'IN H,(C)$'
;***********************************************************
;* IN L,(C) Flags: S Z - H - P/V N C *
;* ^ ^ x ^ x P 0 . *
;***********************************************************
Z_INlc:
mov si,inlc
jmp NEAR Nocde0
inlc: db 'IN L,(C)$'
;***********************************************************
;* IN A,(C) Flags: S Z - H - P/V N C *
;* ^ ^ x ^ x P 0 . *
;***********************************************************
Z_INac:
mov si,inac
jmp NEAR Nocde0
inac: db 'IN A,(C)$'
;***********************************************************
;* IN (HL),(C) Flags: S Z - H - P/V N C *
;* ? ? x ? x ? ? ? *
;***********************************************************
Z_INfc:
mov si,infc
jmp NEAR Nocde0
infc: db 'IN (HL),(C)$'
;***********************************************************
;* IN A,(NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_INan:
mov si,inan
jmp NEAR Nocde1
inan: db 'IN A,(NN)$'
;***********************************************************
;* INI Flags: S Z - H - P/V N C *
;* x ^ x x x x 1 x *
;***********************************************************
Z_INI:
mov si,ini
jmp NEAR Nocde0
ini: db 'INI$'
;***********************************************************
;* IND Flags: S Z - H - P/V N C *
;* x ^ x x x x 1 x *
;***********************************************************
Z_IND:
mov si,ind
jmp NEAR Nocde0
ind: db 'IND$'
;***********************************************************
;* INIR Flags: S Z - H - P/V N C *
;* x 1 x x x x 1 x *
;***********************************************************
Z_INIR:
mov si,inir
jmp NEAR Nocde0
inir: db 'INIR$'
;***********************************************************
;* INDR Flags: S Z - H - P/V N C *
;* x 1 x x x x 1 x *
;***********************************************************
Z_INDR:
mov si,indr
jmp NEAR Nocde0
indr: db 'INDR$'
;***********************************************************
;* OUT (C),B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_OUTcb:
mov si,outcb
jmp NEAR Nocde0
outcb: db 'OUT (C),B$'
;***********************************************************
;* OUT (C),C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_OUTcc:
mov si,outcc
jmp NEAR Nocde0
outcc: db 'OUT (C),C$'
;***********************************************************
;* OUT (C),D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_OUTcd:
mov si,outcd
jmp NEAR Nocde0
outcd: db 'OUT (C),D$'
;***********************************************************
;* OUT (C),E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_OUTce:
mov si,outce
jmp NEAR Nocde0
outce: db 'OUT (C),E$'
;***********************************************************
;* OUT (C),H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_OUTch:
mov si,outch
jmp NEAR Nocde0
outch: db 'OUT (C),H$'
;***********************************************************
;* OUT (C),L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_OUTcl:
mov si,outcl
jmp NEAR Nocde0
outcl: db 'OUT (C),L$'
;***********************************************************
;* OUT (C),A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_OUTca:
mov si,outca
jmp NEAR Nocde0
outca: db 'OUT (C),A$'
;***********************************************************
;* OUT (NN),A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
; used for 8086 interfacing
;***********************************************************
;* OUTI Flags: S Z - H - P/V N C *
;* x ^ x x x x 1 x *
;***********************************************************
Z_OUTI:
mov si,outi
jmp NEAR Nocde0
outi: db 'OUTI$'
;***********************************************************
;* OUTD Flags: S Z - H - P/V N C *
;* x ^ x x x x 1 x *
;***********************************************************
Z_OUTD:
mov si,outd
jmp NEAR Nocde0
outd: db 'OUTD$'
;***********************************************************
;* OTIR Flags: S Z - H - P/V N C *
;* x 1 x x x x 1 x *
;***********************************************************
Z_OTIR:
mov si,otir
jmp NEAR Nocde0
otir: db 'OTIR$'
;***********************************************************
;* OTDR Flags: S Z - H - P/V N C *
;* x 1 x x x x 1 x *
;***********************************************************
Z_OTDR:
mov si,otdr
jmp NEAR Nocde0
otdr: db 'OTDR$'
end

View File

@@ -0,0 +1,268 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* Jump Group *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 10 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Changed all uses of 'Z80' map segment to 'es:Z80'
; - Added 'align=16' to all SEGMENT declarations. (nasm def is align=1)
;
; v1.00 - 28 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
SEGMENT Z80map public align=16
Z80:
SEGMENT .code public align=16
GLOBAL Z_JPx, Z_JPy, Z_JPhl
GLOBAL Z_JP, Z_JPNZ, Z_JPZ, Z_JPNC, Z_JPC, Z_JPPO
GLOBAL Z_JPPE, Z_JPP, Z_JPM
GLOBAL Z_JR, Z_JRNZ, Z_JRZ, Z_JRNC, Z_JRC
GLOBAL Z_DJNZ
; declared in INSTHAND.ASM
EXTERN Z80IX, Z80IY
%include "macros.asm"
;***********************************************************
;* JP NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JP:
mov bp,word [es:Z80+bp]
XinstA
;***********************************************************
;* JP NZ,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JPNZ:
jnz jumpnz
lahf
inc bp
inc bp
XinstB
jumpnz: mov bp,word [es:Z80+bp]
XinstA
;***********************************************************
;* JP Z,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JPZ:
jz jumpz
lahf
inc bp
inc bp
XinstB
jumpz: mov bp,word [es:Z80+bp]
XinstA
;***********************************************************
;* JP NC,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JPNC:
jnc jumpnc
lahf
inc bp
inc bp
XinstB
jumpnc: mov bp,word [es:Z80+bp]
XinstA
;***********************************************************
;* JP C,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JPC:
jc jumpc
lahf
inc bp
inc bp
XinstB
jumpc: mov bp,word [es:Z80+bp]
XinstA
;***********************************************************
;* JP PO,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JPPO:
jpo jumppo
lahf
inc bp
inc bp
XinstB
jumppo: mov bp,word [es:Z80+bp]
XinstA
;***********************************************************
;* JP PE,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JPPE:
jpe jumppe
lahf
inc bp
inc bp
XinstB
jumppe: mov bp,word [es:Z80+bp]
XinstA
;***********************************************************
;* JP P,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JPP:
jns jumpp
lahf
inc bp
inc bp
XinstB
jumpp: mov bp,word [es:Z80+bp]
XinstA
;***********************************************************
;* JP M,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JPM:
js jumpm
lahf
inc bp
inc bp
XinstB
jumpm: mov bp,word [es:Z80+bp]
XinstA
;***********************************************************
;* JP (HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JPhl:
mov bp,bx
XinstA
;***********************************************************
;* JP (IX) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JPx:
mov bp,[Z80IX]
XinstA
;***********************************************************
;* JP (IY) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JPy:
mov bp,[Z80IY]
XinstA
;***********************************************************
;* JR RR Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JR:
lahf
JRx: mov si,ax
mov al,[es:Z80+bp]
inc bp ;points to next instruction
cbw ;label: jr label = FE hex (-2)
add bp,ax
mov ax,si
XinstB
;***********************************************************
;* JR C,RR Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JRC:
jc jrc
lahf
inc bp
XinstB
jrc: jmp Z_JR
;***********************************************************
;* JR NC,RR Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JRNC:
jnc jrnc
lahf
inc bp
XinstB
jrnc: jmp Z_JR
;***********************************************************
;* JR Z,RR Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JRZ:
jz jrz
lahf
inc bp
XinstB
jrz: jmp Z_JR
;***********************************************************
;* JR NZ,RR Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_JRNZ:
jnz jrnz
lahf
inc bp
XinstB
jrnz: jmp Z_JR
;***********************************************************
;* DJNZ RR Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_DJNZ:
lahf
dec ch
jnz djnz
inc bp
XinstB
djnz: jmp JRx
end

View File

@@ -0,0 +1,480 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* 16-bit Load Group *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 10 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Changed all uses of 'Z80' map segment to 'es:Z80'
; - Added 'align=16' to all SEGMENT declarations. (nasm def is align=1)
;
; v1.00 - 28 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
SEGMENT Z80map public align=16
Z80:
SEGMENT .code public align=16
GLOBAL Z_LDxn, Z_LDmx, Z_LDxm, Z_POPx, Z_PUSHx, Z_LDspx
GLOBAL Z_LDyn, Z_LDmy, Z_LDym, Z_POPy, Z_PUSHy, Z_LDspy
GLOBAL Z_LDmbc, Z_LDbcm, Z_LDmde, Z_LDdem, Z_LDmsp, Z_LDspm
GLOBAL Z_LDbcn, Z_LDden, Z_LDhln, Z_LDmhl, Z_LDhlm, Z_LDspn
GLOBAL Z_POPbc, Z_PUSHbc, Z_POPde, Z_PUSHde, Z_POPhl, Z_PUSHhl
GLOBAL Z_POPaf, Z_PUSHaf
GLOBAL Z_LDsphl
; declared in INSTHAND.ASM
EXTERN Z80SP, Z80IX, Z80IY
EXTERN FlagN, FlagX
%include "macros.asm"
;***********************************************************
;* LD BC,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDbcn:
mov cx,word [es:Z80+bp]
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD DE,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDden:
mov dx,word [es:Z80+bp]
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD HL,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDhln:
mov bx,word [es:Z80+bp]
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD SP,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDspn:
mov di,word [es:Z80+bp]
mov [Z80SP],di
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD IX,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDxn:
mov di,word [es:Z80+bp]
mov [Z80IX],di
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD IY,NNNN Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDyn:
mov di,word [es:Z80+bp]
mov [Z80IY],di
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD BC,(NNNN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDbcm:
mov di,word [es:Z80+bp]
mov cx,word [es:Z80+di]
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD DE,(NNNN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDdem:
mov di,word [es:Z80+bp]
mov dx,word [es:Z80+di]
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD HL,(NNNN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDhlm:
mov di,word [es:Z80+bp]
mov bx,word [es:Z80+di]
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD SP,(NNNN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDspm:
mov di,word [es:Z80+bp]
mov si,word [es:Z80+di]
mov [Z80SP],si
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD IX,(NNNN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDxm:
mov di,word [es:Z80+bp]
mov si,word [es:Z80+di]
mov [Z80IX],si
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD IY,(NNNN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDym:
mov di,word [es:Z80+bp]
mov si,word [es:Z80+di]
mov [Z80IY],si
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD (NNNN),BC Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDmbc:
mov di,word [es:Z80+bp]
mov word [es:Z80+di],cx
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD (NNNN),DE Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDmde:
mov di,word [es:Z80+bp]
mov word [es:Z80+di],dx
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD (NNNN),HL Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDmhl:
mov di,word [es:Z80+bp]
mov word [es:Z80+di],bx
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD (NNNN),SP Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDmsp:
mov si,[Z80SP]
mov di,word [es:Z80+bp]
mov word [es:Z80+di],si
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD (NNNN),IX Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDmx:
mov si,[Z80IX]
mov di,word [es:Z80+bp]
mov word [es:Z80+di],si
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD (NNNN),IY Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDmy:
mov si,[Z80IY]
mov di,word [es:Z80+bp]
mov word [es:Z80+di],si
lahf
inc bp
inc bp
XinstB
;***********************************************************
;* LD SP,HL Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDsphl:
mov [Z80SP],bx
XinstA
;***********************************************************
;* LD SP,IX Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDspx:
mov di,[Z80IX]
mov [Z80SP],di
XinstA
;***********************************************************
;* LD SP,IY Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_LDspy:
mov di,[Z80IY]
mov [Z80SP],di
XinstA
;***********************************************************
;* PUSH AF Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_PUSHaf:
pushf
lahf
and ah,11010101b ;reset unused 8086 flags
or ah,[FlagN] ;add in Z80 negative flag
or ah,[FlagX] ;add in Z80 unused flags
mov di,[Z80SP]
dec di
mov BYTE [es:Z80+di],al ;Z80 reg A on stack 1st
dec di
mov BYTE [es:Z80+di],ah ;Z80 flag register last
mov [Z80SP],di
popf
XinstA
;***********************************************************
;* PUSH BC Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_PUSHbc:
lahf
mov di,[Z80SP]
dec di
dec di
mov word [es:Z80+di],cx
mov [Z80SP],di
XinstB
;***********************************************************
;* PUSH DE Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_PUSHde:
lahf
mov di,[Z80SP]
dec di
dec di
mov word [es:Z80+di],dx
mov [Z80SP],di
XinstB
;***********************************************************
;* PUSH HL Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_PUSHhl:
lahf
mov di,[Z80SP]
dec di
dec di
mov word [es:Z80+di],bx
mov [Z80SP],di
XinstB
;***********************************************************
;* PUSH IX Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_PUSHx:
lahf
mov di,[Z80SP]
dec di
dec di
mov [Z80SP],di
mov si,[Z80IX]
mov word [es:Z80+di],si
XinstB
;***********************************************************
;* PUSH IY Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_PUSHy:
lahf
mov di,[Z80SP]
dec di
dec di
mov [Z80SP],di
mov si,[Z80IY]
mov word [es:Z80+di],si
XinstB
;***********************************************************
;* POP AF Flags: S Z - H - P/V N C *
;* ^ ^ x ^ x ^ ^ ^ *
;***********************************************************
Z_POPaf:
mov di,[Z80SP]
mov ah,[es:Z80+di]
inc di
mov al,[es:Z80+di]
inc di
mov [Z80SP],di
mov [FlagN],ah
and BYTE [FlagN],00000010b
mov [FlagX],ah
and BYTE [FlagX],00101000b
and ah,11010101b
XinstB
;***********************************************************
;* POP BC Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_POPbc:
lahf
mov di,[Z80SP]
mov cx,word [es:Z80+di]
inc di
inc di
mov [Z80SP],di
XinstB
;***********************************************************
;* POP DE Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_POPde:
lahf
mov di,[Z80SP]
mov dx,word [es:Z80+di]
inc di
inc di
mov [Z80SP],di
XinstB
;***********************************************************
;* POP HL Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_POPhl:
lahf
mov di,[Z80SP]
mov bx,word [es:Z80+di]
inc di
inc di
mov [Z80SP],di
XinstB
;***********************************************************
;* POP IX Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_POPx:
lahf
mov di,[Z80SP]
mov si,word [es:Z80+di]
mov [Z80IX],si
inc di
inc di
mov [Z80SP],di
XinstB
;***********************************************************
;* POP IY Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_POPy:
lahf
mov di,[Z80SP]
mov si,word [es:Z80+di]
mov [Z80IY],si
inc di
inc di
mov [Z80SP],di
XinstB
end

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,99 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* Macros *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 10 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Added 'BITS 16' and 'CPU 8086' and make all ASM files include this file.
; - Changed all uses of 'Z80' map segment to 'es:Z80'
;
; v1.00 - 5 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
BITS 16
CPU 8086
EXTERN T0
%MACRO XinstA 0
lahf ;get Z80 reg F into reg ah
mov si,ax ;save Z80 regs A and F
xor ah,ah
mov al,[es:Z80+bp] ;get Z80 opcode
mov di,ax
shl di,1 ;T0 instruction table offset
inc bp ;next Z80 PC
mov ax,si ;restore Z80 reg A and F
sahf ;set 8086 Flags with Z80 reg F (ah)
jmp WORD [T0+di]
%ENDMACRO
%MACRO XinstB 0
mov si,ax ;save Z80 regs A and F
xor ah,ah
mov al,[es:Z80+bp] ;get Z80 opcode
mov di,ax
shl di,1 ;T0 instruction table offset
inc bp ;next Z80 PC
mov ax,si ;restore Z80 reg A and F
sahf ;set 8086 Flags with Z80 reg F (ah)
jmp WORD [T0+di]
%ENDMACRO
%MACRO XinstC 0
lahf ;get Z80 reg F into reg ah
and ah,11111011b ;reset P/V to indicate no overflow
mov si,ax ;save Z80 regs A and F
xor ah,ah
mov al,[es:Z80+bp] ;get Z80 opcode
mov di,ax
shl di,1 ;T0 instruction table offset
inc bp ;next Z80 PC
mov ax,si ;restore Z80 reg A and F
sahf ;set 8086 Flags with Z80 reg F (ah)
jmp WORD [T0+di]
%ENDMACRO
%MACRO XinstD 0
lahf ;get Z80 reg F into reg ah
or ah,00000100b ;set P/V to indicate overflow
mov si,ax ;save Z80 regs A and F
xor ah,ah
mov al,[es:Z80+bp] ;get Z80 opcode
mov di,ax
shl di,1 ;T0 instruction table offset
inc bp ;next Z80 PC
mov ax,si ;restore Z80 reg A and F
sahf ;set 8086 Flags with Z80 reg F (ah)
jmp WORD [T0+di]
%ENDMACRO

View File

@@ -0,0 +1,411 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* Main assembly module *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 20 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Removed one occurence of label NEAR from: 'lea dx,[NEAR criter]'
; - Changed 'lea' instructions to 'mov'.
; - Removed 'seg' from 'mov ax,seg stkseg' and 'mov bx,seg Zend'
; - Removed 'ss:' from 'mov bx,ss:topstk'
; - Added '..start:' before the 'Z80emu:' label.
; - Changed all uses of Z80 map segment to 'es:Z80'
; - Added 'align=16' to all SEGMENT declarations. (nasm def is align=1)
; - Changed 'SgnMsg' version to use APPVER passed from Makefile.
; - Changed command line drive options from A: and B: to now use -A and -B
; and also allow Z80 system parameters to be flagged even if floppy
; options are specified.
;
; v1.00 - 29 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
SEGMENT Z80map public align=16
Z80:
SEGMENT .code public align=16
GLOBAL Z80res, Z80ext, Z80opc
GLOBAL BufSeg, VidSeg, VidBuf
GLOBAL prmbuf, prmflg, vidoff
; declared in WINDOW.ASM
EXTERN OpnWnd, ClsWnd
EXTERN PrnStr, GetKey, EraScr, HdeCur
; declared in HARDWARE.ASM
EXTERN bnkini, bnkres
EXTERN newkbd, oldkbd
EXTERN rdflop, rdhard
EXTERN HrdFle, Handle
; declared in FUNCTION.ASM
EXTERN criter, fboot, SysErr
EXTERN BufCnt, BootDr
; declared in INSTHAND.ASM
EXTERN FlagX, FlagN, FlagNx, IFF
EXTERN Z80I, Z80R, Z80SP, Z80IX, Z80IY
EXTERN Z80AF, Z80BC, Z80DE, Z80HL
%include "macros.asm"
BLKMAX equ 64 ;maximum number of 16 K-byte memory blocks
prmbuf resb 80 ;buffer for command tail parameters
BufSeg resw BLKMAX ;table of segments for 16 K-byte blocks
VidSeg resw 1
VidBuf resw 1
VidMde resb 1
vidoff db 0 ;disable output to video drivers flag
prmflg db 0 ;command tail passed flag
flpdrv db 0 ;floppy to boot up from, 0=A or 1=B
flpflg db 0 ;boot from floppy flag
CtrlC resb 1 ;saved state of Ctrl-C flag
; Z80 Emulator execution begins here
..start:
Z80emu:
mov ax,stkseg
mov bx,topstk
cli
mov ss,ax ;set stack segment register
mov sp,bx ;set stack pointer register
sti
mov ax,cs
mov ds,ax ;set data segment=code segment
; Save command tail in Program Segment Prifix (PSP)
push ds
push es
mov si,0080h ;source offset
mov di,prmbuf ;destination offset buffer
mov cx,80 ;amount to move
mov ax,es
mov ds,ax ;set source segment (PSP)
mov ax,cs
mov es,ax ;set destination segment
cld ;move forward
rep movsb
pop es
pop ds
; Check command tail in Program Segment Prifix (PSP)
mov si,0080h
mov cl,[es:si] ;size of command tail (ES=PSP)
mov di,si ;copy of command tail offset
xor ch,ch
add di,cx ;point to last character
chkspc: cmp byte [es:di],' ' ;trailing space character ?
jnz chkprm
dec cl
jz setvid
dec di ;work backwards
jmp chkspc
chkprm: or cl,cl
jz setvid ;no tail remaining if count is 0
dec cl
inc si
mov al,[es:si] ;get character from command tail
cmp al,' ' ;ignore leading space characters
jz chkprm
cmp al,'-' ;leading hyphen character ?
jnz chkdir ;no, then check for redirection
or cl,cl
jz setvid ;error in option if end of tail
inc si
mov al,[es:si]
and al,11011111b ;convert to uppercase
cmp al,'A' ;force boot from A: ?
jz flpopt
cmp al,'B' ;force boot from B: ?
jnz setvid ;error in floppy selection
flpopt: mov [DrvChr],al ;insert letter into message
sub al,'A'
mov [flpdrv],al ;drive code of floppy to be booted
mov BYTE [flpflg],0ffh ;boot from floppy flag
dec cl ;any more tail left ?
jz setvid
inc si
chkdir: cmp BYTE [es:si],'<' ;DOS input redirection ?
jz setvid
cmp BYTE [es:si],'>' ;DOS output redirection ?
jz setvid
mov BYTE [prmflg],0ffh ;set command tail flag true
mov BYTE [vidoff],0ffh ;disable video output
; Determine and set video display mode
setvid: mov ah,00fh ;get current video mode function
int 010h
mov [VidMde],al ;save video mode
int 011h ;get equipment list interrupt
and al,00110000b ;keep initial video mode bits
mov ah,007h ;monochrome 25 * 80 text display
mov WORD [VidSeg],0b000h ;monochrome video segment
or al,al ;unused video system ?
jz MonVid
cmp al,00110000b ;monochrome video system ?
jz MonVid
mov ah,002h ;colour 25 * 80 text display
mov WORD [VidSeg],0b800h ;colour video segment
MonVid: cmp BYTE [prmflg],0 ;do not set video if command tail
jnz seterr
mov al,ah
mov ah,000h ;set video mode function
int 010h
; Setup local DOS critical error handler
seterr: mov ah,025h ;set interrupt function
mov al,024h ;critical error handler vector
mov dx,criter
int 21h ;change vector via DOS
; Setup keyboard intercept and Ctrl C flag
mov ah,033h ;get/set Ctrl-C flag function
mov al,000h ;get function
int 021h
mov [CtrlC],al ;save flag for later
mov ah,033h ;get/set Ctrl-C flag function
mov al,001h ;set function
xor dl,dl ;turn of Ctrl-C action
int 021h
call NEAR newkbd
; Resize memory for Z80 Emulator program
mov ax,es ;get PSP address in ES
mov bx,Zend
sub bx,ax ;program size in BX
mov ah,04ah ;modify allocated memory function
push ds
int 021h
pop ds
jnc Z80mp0
jmp ErrAlo
; Allocate memory for Z80 address map (2 maps of 64k)
Z80mp0: mov ah,048h ;allocate memory function
mov bx,4096 ;64K-bytes for Z80 bank 0
int 021h
mov cx,ax ;save bank #0 segment address
jnc Z80mp1
jmp ErrAlo
Z80mp1: mov ah,048h ;allocate memory function
mov bx,4096 ;64K-bytes for Z80 bank 1
int 021h
call NEAR bnkini ;initialize variables
jnc AloWnd
jmp ErrAlo
; Allocate memory for window useage
AloWnd: mov ah,048h ;allocate memory function
mov bx,1024 ;allocate 16 K-bytes
int 021h
jnc VidSet
jmp ErrAlo
VidSet: mov [VidBuf],ax ;save segment of 16 K-byte block
; Allocate remaining memory in 16 K-byte blocks
mov BYTE [BufCnt],0 ;set block counter to 0
xor bx,bx ;set table offset to 0
nxtalo: push bx
mov ah,048h ;allocate memory function
mov bx,1024 ;allocate 16 K-bytes at a time
push ds
push es
int 021h
pop es
pop ds
pop bx
jc OpnHrd
mov WORD [BufSeg+bx],ax ;save segment of 16 K-byte block
inc BYTE [BufCnt] ;count 16 K-byte blocks
inc bx
inc bx
cmp BYTE [BufCnt],BLKMAX ;allocate upto 64 blocks of memory
jnz nxtalo
; Open Z80 hard disk file image on current drive
OpnHrd: mov ah,019h ;get current disk function
int 021h ;A=0, B=1, C=2, etc
cmp al,02h
jc Z80res ;HDD file not supported on floppy
mov dx,Fname ;offset address of ASCIIZ string
mov ah,043h ;get/set file attributes function
mov al,001h ;set attribute function
mov cx,0 ;read/write file attribute
int 021h ;change attribute
mov dx,Fname ;offset address of ASCIIZ string
mov ah,03dh ;open file function
mov al,002h ;access mode, 2=read/write
int 021h ;open disk file
jc Z80res ;HDD file not found if carry
mov [Handle],ax ;save file handle
mov ah,019h ;get current disk function
int 021h
mov [HrdFle],al ;save drive code
; Z80 reset point, check what drive to boot from
Z80res: call NEAR bnkres ;reset bank #0, #1
call NEAR EraScr ;clear the screen
cmp BYTE [flpflg],0 ;force boot up from floppy ?
jnz LdBoot
cmp BYTE [HrdFle],0ffh ;HDD file present ?
jz Prompt
mov BYTE [es:Z80+0080h],0 ;kill any existing $C3 jump code
mov dl,[HrdFle] ;HDD file drive
mov [BootDr],dl ;save boot drive
xor ch,ch ;track #0
mov cl,1 ;sector #1
mov bx,0080h ;BX=buffer
call NEAR rdhard ;read 1st sector from HDD file
jmp chkcde
; Prompt the user for a Z80 system disk in drive A
Prompt: mov dh,9
mov dl,18
mov ch,15
mov cl,62
call NEAR OpnWnd
mov si,SgnMsg
call NEAR PrnStr
call NEAR HdeCur ;hide the cursor
mov si,SgnKey ;keys ESC, ^C, ENTER
call NEAR GetKey
call NEAR ClsWnd
cmp al,27 ;ESC key pressed ?
jz Z80abt
cmp al,3 ;Ctrl-C key pressed ?
jz Z80abt ;fall through if ENTER key
; Load 1st sector from Z80 system disk in drive A
LdBoot: mov BYTE [es:Z80+0080h],0 ;kill any existing $C3 jump code
mov dh,0 ;side #0
mov dl,[flpdrv] ;drive code
mov [BootDr],dl ;save boot drive
mov ch,0 ;track #0
mov cl,1 ;sector #1
mov al,2 ;sector size code (2=512)
mov bx,0080h ;BX=buffer
call NEAR rdflop ;read 1st sector from floppy disk
chkcde: or al,al
jz loaded
jmp NEAR fboot ;failed to boot disk if here
loaded: cmp BYTE [es:Z80+0080h],0c3h ;Z80 jump in 1st byte of sector ?
jz Z80exe
jmp NEAR SysErr ;system not designed for Z80 Emulator
Z80abt: jmp Z80ext ;exit the Z80 Emulator program
; Reset Z80 registers and execute Z80 code
Z80exe: xor ax,ax ;Z80 reg A=0
mov cx,ax ;Z80 reg BC=0
mov dx,ax ;Z80 reg DE=0
mov bx,ax ;Z80 reg HL=0
mov [Z80IX],ax ;Z80 reg IX=0
mov [Z80IY],ax ;Z80 reg IY=0
mov [Z80AF],ax ;Z80 reg AF'=0
mov [Z80BC],ax ;Z80 reg BC'=0
mov [Z80DE],ax ;Z80 reg DE'=0
mov [Z80HL],ax ;Z80 reg HL'=0
mov [FlagX],ah ;Z80 unused flag bits = 0
mov [FlagN],ah ;Z80 N flag=0
mov [FlagNx],ah ;Z80 N' flag=0
mov [IFF],ah ;Z80 interrupt Flip Flop = 0 (DI)
sahf ;Z80 reg F=0
mov bp,0080h ;Z80 reg PC=0080 hex
mov WORD [Z80SP],0ffffh ;Z80 reg SP=FFFF hex
Z80opc: XinstA ;execute 1st Z80 instruction
; Insufficient memory for Z80 map / Window buffers
ErrAlo: mov dh,11
mov dl,20
mov ch,14
mov cl,59
call NEAR OpnWnd
mov si,MemMsg
call NEAR PrnStr
call NEAR HdeCur ;hide the cursor
mov si,MemKey
call NEAR GetKey ;wait for ESC key
call NEAR ClsWnd
; Exit the Z80 Emulator through here
Z80ext: cmp BYTE [HrdFle],0ffh ;Z80 hard disk file image opened ?
jz NotHDD
mov ah,03eh ;close file function
mov bx,[Handle]
int 021h ;flush and close file
mov dx,Fname ;offset address of ASCIIZ string
mov ah,043h ;get/set file attributes function
mov al,001h ;set attribute function
mov cx,001h ;read only file attribute
int 021h ;change attribute
NotHDD: call NEAR oldkbd
mov ah,033h ;get/set Ctrl-C flag function
mov al,001h ;set function
mov dl,[CtrlC] ;restore original Ctrl-C flag
int 021h
cmp BYTE [prmflg],0 ;was a command tail passed ?
jnz retcde
mov al,[VidMde] ;set original video mode
and al,01111111b ;force screen to be cleared
mov ah,000h ;set video mode function
int 010h
retcde: mov ax,4c00h ;return to DOS with code function
int 21h
SgnKey db 27, 3, 13, '$'
MemKey db 27, '$'
SgnMsg db ' Z80EM86-', APPVER, ' Z80 CPU Emulator', 0dh, 0ah
db ' Copyright (C) 1992-2009 Stewart Kay', 0dh, 0ah, 0ah
db ' Insert Z80 system disk into drive '
DrvChr db 'A:', 0dh, 0ah
db ' Press ENTER when ready$'
MemMsg db 'Insufficient memory for Z80 Emulator', 0dh, 0ah
db ' Press ESC to return to DOS$'
Fname db 'Z80HDD.DSK', 0
; Local stack area setup here
SEGMENT stkseg align=16
resw 256 ;reserve space for stack
topstk equ $
; Empty segment for finding program size
SEGMENT Zend align=16
end

View File

@@ -0,0 +1,736 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* Bit Reset Group *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 10 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Changed all uses of 'Z80' map segment to 'es:Z80'
; - Added 'align=16' to all SEGMENT declarations. (nasm def is align=1)
;
; v1.00 - 29 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
SEGMENT Z80map public align=16
Z80:
SEGMENT .code public align=16
GLOBAL Z_RES0w, Z_RES1w, Z_RES2w, Z_RES3w, Z_RES4w, Z_RES5w, Z_RES6w, Z_RES7w
GLOBAL Z_RES0v, Z_RES1v, Z_RES2v, Z_RES3v, Z_RES4v, Z_RES5v, Z_RES6v, Z_RES7v
GLOBAL Z_RES0b, Z_RES0c, Z_RES0d, Z_RES0e, Z_RES0h, Z_RES0l, Z_RES0z, Z_RES0a
GLOBAL Z_RES1b, Z_RES1c, Z_RES1d, Z_RES1e, Z_RES1h, Z_RES1l, Z_RES1z, Z_RES1a
GLOBAL Z_RES2b, Z_RES2c, Z_RES2d, Z_RES2e, Z_RES2h, Z_RES2l, Z_RES2z, Z_RES2a
GLOBAL Z_RES3b, Z_RES3c, Z_RES3d, Z_RES3e, Z_RES3h, Z_RES3l, Z_RES3z, Z_RES3a
GLOBAL Z_RES4b, Z_RES4c, Z_RES4d, Z_RES4e, Z_RES4h, Z_RES4l, Z_RES4z, Z_RES4a
GLOBAL Z_RES5b, Z_RES5c, Z_RES5d, Z_RES5e, Z_RES5h, Z_RES5l, Z_RES5z, Z_RES5a
GLOBAL Z_RES6b, Z_RES6c, Z_RES6d, Z_RES6e, Z_RES6h, Z_RES6l, Z_RES6z, Z_RES6a
GLOBAL Z_RES7b, Z_RES7c, Z_RES7d, Z_RES7e, Z_RES7h, Z_RES7l, Z_RES7z, Z_RES7a
; declared in INSTHAND.ASM
EXTERN Z80IX, Z80IY
%include "macros.asm"
;***********************************************************
;* RES 0,B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES0b:
lahf
and ch,11111110b
XinstB
;***********************************************************
;* RES 1,B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES1b:
lahf
and ch,11111101b
XinstB
;***********************************************************
;* RES 2,B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES2b:
lahf
and ch,11111011b
XinstB
;***********************************************************
;* RES 3,B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES3b:
lahf
and ch,11110111b
XinstB
;***********************************************************
;* RES 4,B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES4b:
lahf
and ch,11101111b
XinstB
;***********************************************************
;* RES 5,B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES5b:
lahf
and ch,11011111b
XinstB
;***********************************************************
;* RES 6,B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES6b:
lahf
and ch,10111111b
XinstB
;***********************************************************
;* RES 7,B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES7b:
lahf
and ch,01111111b
XinstB
;***********************************************************
;* RES 0,C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES0c:
lahf
and cl,11111110b
XinstB
;***********************************************************
;* RES 1,C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES1c:
lahf
and cl,11111101b
XinstB
;***********************************************************
;* RES 2,C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES2c:
lahf
and cl,11111011b
XinstB
;***********************************************************
;* RES 3,C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES3c:
lahf
and cl,11110111b
XinstB
;***********************************************************
;* RES 4,C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES4c:
lahf
and cl,11101111b
XinstB
;***********************************************************
;* RES 5,C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES5c:
lahf
and cl,11011111b
XinstB
;***********************************************************
;* RES 6,C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES6c:
lahf
and cl,10111111b
XinstB
;***********************************************************
;* RES 7,C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES7c:
lahf
and cl,01111111b
XinstB
;***********************************************************
;* RES 0,D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES0d:
lahf
and dh,11111110b
XinstB
;***********************************************************
;* RES 1,D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES1d:
lahf
and dh,11111101b
XinstB
;***********************************************************
;* RES 2,D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES2d:
lahf
and dh,11111011b
XinstB
;***********************************************************
;* RES 3,D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES3d:
lahf
and dh,11110111b
XinstB
;***********************************************************
;* RES 4,D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES4d:
lahf
and dh,11101111b
XinstB
;***********************************************************
;* RES 5,D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES5d:
lahf
and dh,11011111b
XinstB
;***********************************************************
;* RES 6,D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES6d:
lahf
and dh,10111111b
XinstB
;***********************************************************
;* RES 7,D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES7d:
lahf
and dh,01111111b
XinstB
;***********************************************************
;* RES 0,E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES0e:
lahf
and dl,11111110b
XinstB
;***********************************************************
;* RES 1,E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES1e:
lahf
and dl,11111101b
XinstB
;***********************************************************
;* RES 2,E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES2e:
lahf
and dl,11111011b
XinstB
;***********************************************************
;* RES 3,E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES3e:
lahf
and dl,11110111b
XinstB
;***********************************************************
;* RES 4,E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES4e:
lahf
and dl,11101111b
XinstB
;***********************************************************
;* RES 5,E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES5e:
lahf
and dl,11011111b
XinstB
;***********************************************************
;* RES 6,E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES6e:
lahf
and dl,10111111b
XinstB
;***********************************************************
;* RES 7,E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES7e:
lahf
and dl,01111111b
XinstB
;***********************************************************
;* RES 0,H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES0h:
lahf
and bh,11111110b
XinstB
;***********************************************************
;* RES 1,H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES1h:
lahf
and bh,11111101b
XinstB
;***********************************************************
;* RES 2,H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES2h:
lahf
and bh,11111011b
XinstB
;***********************************************************
;* RES 3,H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES3h:
lahf
and bh,11110111b
XinstB
;***********************************************************
;* RES 4,H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES4h:
lahf
and bh,11101111b
XinstB
;***********************************************************
;* RES 5,H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES5h:
lahf
and bh,11011111b
XinstB
;***********************************************************
;* RES 6,H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES6h:
lahf
and bh,10111111b
XinstB
;***********************************************************
;* RES 7,H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES7h:
lahf
and bh,01111111b
XinstB
;***********************************************************
;* RES 0,L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES0l:
lahf
and bl,11111110b
XinstB
;***********************************************************
;* RES 1,L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES1l:
lahf
and bl,11111101b
XinstB
;***********************************************************
;* RES 2,L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES2l:
lahf
and bl,11111011b
XinstB
;***********************************************************
;* RES 3,L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES3l:
lahf
and bl,11110111b
XinstB
;***********************************************************
;* RES 4,L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES4l:
lahf
and bl,11101111b
XinstB
;***********************************************************
;* RES 5,L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES5l:
lahf
and bl,11011111b
XinstB
;***********************************************************
;* RES 6,L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES6l:
lahf
and bl,10111111b
XinstB
;***********************************************************
;* RES 7,L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES7l:
lahf
and bl,01111111b
XinstB
;***********************************************************
;* RES 0,A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES0a:
lahf
and al,11111110b
XinstB
;***********************************************************
;* RES 1,A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES1a:
lahf
and al,11111101b
XinstB
;***********************************************************
;* RES 2,A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES2a:
lahf
and al,11111011b
XinstB
;***********************************************************
;* RES 3,A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES3a:
lahf
and al,11110111b
XinstB
;***********************************************************
;* RES 4,A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES4a:
lahf
and al,11101111b
XinstB
;***********************************************************
;* RES 5,A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES5a:
lahf
and al,11011111b
XinstB
;***********************************************************
;* RES 6,A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES6a:
lahf
and al,10111111b
XinstB
;***********************************************************
;* RES 7,A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES7a:
lahf
and al,01111111b
XinstB
;***********************************************************
;* RES 0,(HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES0z:
lahf
and BYTE [es:Z80+bx],11111110b
XinstB
;***********************************************************
;* RES 1,(HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES1z:
lahf
and BYTE [es:Z80+bx],11111101b
XinstB
;***********************************************************
;* RES 2,(HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES2z:
lahf
and BYTE [es:Z80+bx],11111011b
XinstB
;***********************************************************
;* RES 3,(HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES3z:
lahf
and BYTE [es:Z80+bx],11110111b
XinstB
;***********************************************************
;* RES 4,(HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES4z:
lahf
and BYTE [es:Z80+bx],11101111b
XinstB
;***********************************************************
;* RES 5,(HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES5z:
lahf
and BYTE [es:Z80+bx],11011111b
XinstB
;***********************************************************
;* RES 6,(HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES6z:
lahf
and BYTE [es:Z80+bx],10111111b
XinstB
;***********************************************************
;* RES 7,(HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES7z:
lahf
and BYTE [es:Z80+bx],01111111b
XinstB
;***********************************************************
;* RES 0,(IX+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;* RES 0,(IY+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES0w:
Z_RES0v:
lahf
and BYTE [es:Z80+si],11111110b
XinstB
;***********************************************************
;* RES 1,(IX+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;* RES 1,(IY+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES1w:
Z_RES1v:
lahf
and BYTE [es:Z80+si],11111101b
XinstB
;***********************************************************
;* RES 2,(IX+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;* RES 2,(IY+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES2w:
Z_RES2v:
lahf
and BYTE [es:Z80+si],11111011b
XinstB
;***********************************************************
;* RES 3,(IX+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;* RES 3,(IY+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES3w:
Z_RES3v:
lahf
and BYTE [es:Z80+si],11110111b
XinstB
;***********************************************************
;* RES 4,(IX+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;* RES 4,(IY+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES4w:
Z_RES4v:
lahf
and BYTE [es:Z80+si],11101111b
XinstB
;***********************************************************
;* RES 5,(IX+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;* RES 5,(IY+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES5w:
Z_RES5v:
lahf
and BYTE [es:Z80+si],11011111b
XinstB
;***********************************************************
;* RES 6,(IX+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;* RES 6,(IY+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES6w:
Z_RES6v:
lahf
and BYTE [es:Z80+si],10111111b
XinstB
;***********************************************************
;* RES 7,(IX+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;* RES 7,(IY+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_RES7w:
Z_RES7v:
lahf
and BYTE [es:Z80+si],01111111b
XinstB
end

View File

@@ -0,0 +1,958 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* Rotate and Shift Group *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 10 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Changed all uses of 'Z80' map segment to 'es:Z80'
; - Added 'align=16' to all SEGMENT declarations. (nasm def is align=1)
;
; v1.00 - 29 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
SEGMENT Z80map public align=16
Z80:
SEGMENT .code public align=16
GLOBAL Z_RLCw, Z_RRCw, Z_RLw, Z_RRw, Z_SLAw, Z_SRAw, Z_SRLw
GLOBAL Z_RLCv, Z_RRCv, Z_RLv, Z_RRv, Z_SLAv, Z_SRAv, Z_SRLv
GLOBAL Z_RLCA, Z_RRCA, Z_RLA, Z_RRA
GLOBAL Z_RLD, Z_RRD
GLOBAL Z_RLCb, Z_RLCc, Z_RLCd, Z_RLCe, Z_RLCh, Z_RLCl, Z_RLCz, Z_RLCa
GLOBAL Z_RRCb, Z_RRCc, Z_RRCd, Z_RRCe, Z_RRCh, Z_RRCl, Z_RRCz, Z_RRCa
GLOBAL Z_RLb, Z_RLc, Z_RLd, Z_RLe, Z_RLh, Z_RLl, Z_RLz, Z_RLa
GLOBAL Z_RRb, Z_RRc, Z_RRd, Z_RRe, Z_RRh, Z_RRl, Z_RRz, Z_RRa
GLOBAL Z_SLAb, Z_SLAc, Z_SLAd, Z_SLAe, Z_SLAh, Z_SLAl, Z_SLAz, Z_SLAa
GLOBAL Z_SRAb, Z_SRAc, Z_SRAd, Z_SRAe, Z_SRAh, Z_SRAl, Z_SRAz, Z_SRAa
GLOBAL Z_SRLb, Z_SRLc, Z_SRLd, Z_SRLe, Z_SRLh, Z_SRLl, Z_SRLz, Z_SRLa
; declared in INSTHAND.ASM
EXTERN Z80IX, Z80IY, FlagN
%include "macros.asm"
svebyt resb 1
;***********************************************************
;* RLCA Flags: S Z - H - P/V N C *
;* . . x 0 x . 0 ^ *
;***********************************************************
Z_RLCA:
rol al,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* RLA Flags: S Z - H - P/V N C *
;* . . x 0 x . 0 ^ *
;***********************************************************
Z_RLA:
rcl al,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* RRCA Flags: S Z - H - P/V N C *
;* . . x 0 x . 0 ^ *
;***********************************************************
Z_RRCA:
ror al,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* RRA Flags: S Z - H - P/V N C *
;* . . x 0 x . 0 ^ *
;***********************************************************
Z_RRA:
rcr al,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* RLC B Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLCb:
rol ch,1
mov BYTE [FlagN],0
inc ch
dec ch
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RLC C Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLCc:
rol cl,1
mov BYTE [FlagN],0
inc cl
dec cl
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RLC D Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLCd:
rol dh,1
mov BYTE [FlagN],0
inc dh
dec dh
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RLC E Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLCe:
rol dl,1
mov BYTE [FlagN],0
inc dl
dec dl
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RLC H Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLCh:
rol bh,1
mov BYTE [FlagN],0
inc bh
dec bh
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RLC L Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLCl:
rol bl,1
mov BYTE [FlagN],0
inc bl
dec bl
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RLC A Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLCa:
rol al,1
mov BYTE [FlagN],0
inc al
dec al
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RLC (HL) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLCz:
rol BYTE [es:Z80+bx],1
mov BYTE [FlagN],0
inc BYTE [es:Z80+bx]
dec BYTE [es:Z80+bx]
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RLC (IX+NN) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;* RLC (IY+NN) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLCw:
Z_RLCv:
rol BYTE [es:Z80+si],1
mov BYTE [FlagN],0
inc BYTE [es:Z80+si]
dec BYTE [es:Z80+si]
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RL B Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLb:
rcl ch,1
mov BYTE [FlagN],0
inc ch
dec ch
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RL C Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLc:
rcl cl,1
mov BYTE [FlagN],0
inc cl
dec cl
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RL D Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLd:
rcl dh,1
mov BYTE [FlagN],0
inc dh
dec dh
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RL E Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLe:
rcl dl,1
mov BYTE [FlagN],0
inc dl
dec dl
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RL H Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLh:
rcl bh,1
mov BYTE [FlagN],0
inc bh
dec bh
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RL L Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLl:
rcl bl,1
mov BYTE [FlagN],0
inc bl
dec bl
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RL A Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLa:
rcl al,1
mov BYTE [FlagN],0
inc al
dec al
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RL (HL) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLz:
rcl BYTE [es:Z80+bx],1
mov BYTE [FlagN],0
inc BYTE [es:Z80+bx]
dec BYTE [es:Z80+bx]
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RL (IX+NN) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;* RL (IY+NN) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RLw:
Z_RLv:
rcl BYTE [es:Z80+si],1
mov BYTE [FlagN],0
inc BYTE [es:Z80+si]
dec BYTE [es:Z80+si]
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RRC B Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRCb:
ror ch,1
mov BYTE [FlagN],0
inc ch
dec ch
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RRC C Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRCc:
ror cl,1
mov BYTE [FlagN],0
inc cl
dec cl
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RRC D Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRCd:
ror dh,1
mov BYTE [FlagN],0
inc dh
dec dh
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RRC E Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRCe:
ror dl,1
mov BYTE [FlagN],0
inc dl
dec dl
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RRC H Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRCh:
ror bh,1
mov BYTE [FlagN],0
inc bh
dec bh
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RRC L Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRCl:
ror bl,1
mov BYTE [FlagN],0
inc bl
dec bl
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RRC A Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRCa:
ror al,1
mov BYTE [FlagN],0
inc al
dec al
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RRC (HL) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRCz:
ror BYTE [es:Z80+bx],1
mov BYTE [FlagN],0
inc BYTE [es:Z80+bx]
dec BYTE [es:Z80+bx]
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RRC (IX+NN) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;* RRC (IY+NN) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRCw:
Z_RRCv:
ror BYTE [es:Z80+si],1
mov BYTE [FlagN],0
inc BYTE [es:Z80+si]
dec BYTE [es:Z80+si]
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RR B Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRb:
rcr ch,1
mov BYTE [FlagN],0
inc ch
dec ch
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RR C Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRc:
rcr cl,1
mov BYTE [FlagN],0
inc cl
dec cl
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RR D Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRd:
rcr dh,1
mov BYTE [FlagN],0
inc dh
dec dh
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RR E Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRe:
rcr dl,1
mov BYTE [FlagN],0
inc dl
dec dl
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RR H Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRh:
rcr bh,1
mov BYTE [FlagN],0
inc bh
dec bh
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RR L Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRl:
rcr bl,1
mov BYTE [FlagN],0
inc bl
dec bl
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RR A Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRa:
rcr al,1
mov BYTE [FlagN],0
inc al
dec al
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RR (HL) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRz:
rcr BYTE [es:Z80+bx],1
mov BYTE [FlagN],0
inc BYTE [es:Z80+bx]
dec BYTE [es:Z80+bx]
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RR (IX+NN) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;* RR (IY+NN) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_RRw:
Z_RRv:
rcr BYTE [es:Z80+si],1
mov BYTE [FlagN],0
inc BYTE [es:Z80+si]
dec BYTE [es:Z80+si]
lahf
and ah,11101111b
XinstB
;***********************************************************
;* SLA B Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SLAb:
shl ch,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SLA C Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SLAc:
shl cl,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SLA D Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SLAd:
shl dh,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SLA E Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SLAe:
shl dl,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SLA H Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SLAh:
shl bh,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SLA L Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SLAl:
shl bl,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SLA A Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SLAa:
shl al,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SLA (HL) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SLAz:
shl BYTE [es:Z80+bx],1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SLA (IX+NN) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;* SLA (IY+NN) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SLAw:
Z_SLAv:
shl BYTE [es:Z80+si],1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRA B Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRAb:
sar ch,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRA C Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRAc:
sar cl,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRA D Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRAd:
sar dh,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRA E Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRAe:
sar dl,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRA H Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRAh:
sar bh,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRA L Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRAl:
sar bl,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRA A Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRAa:
sar al,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRA (HL) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRAz:
sar BYTE [es:Z80+bx],1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRA (IX+NN) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;* SRA (IY+NN) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRAw:
Z_SRAv:
sar BYTE [es:Z80+si],1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRL B Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRLb:
shr ch,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRL C Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRLc:
shr cl,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRL D Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRLd:
shr dh,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRL E Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRLe:
shr dl,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRL H Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRLh:
shr bh,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRL L Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRLl:
shr bl,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRL A Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRLa:
shr al,1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRL (HL) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRLz:
shr BYTE [es:Z80+bx],1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* SRL (IX+NN) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;* SRL (IY+NN) Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 ^ *
;***********************************************************
Z_SRLw:
Z_SRLv:
shr BYTE [es:Z80+si],1
lahf
and ah,11101111b
mov BYTE [FlagN],0
XinstB
;***********************************************************
;* RLD Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 . *
;***********************************************************
Z_RLD:
pushf ;must save C flag
mov [svebyt],al
and BYTE [svebyt],00001111b
and al,11110000b
mov ah,[es:Z80+bx]
shr ah,1
shr ah,1
shr ah,1
shr ah,1
shl BYTE [es:Z80+bx],1
shl BYTE [es:Z80+bx],1
shl BYTE [es:Z80+bx],1
shl BYTE [es:Z80+bx],1
or al,ah
mov ah,[svebyt]
or BYTE [es:Z80+bx],ah
popf
mov BYTE [FlagN],0
inc al
dec al
lahf
and ah,11101111b
XinstB
;***********************************************************
;* RRD Flags: S Z - H - P/V N C *
;* ^ ^ x 0 x P 0 . *
;***********************************************************
Z_RRD:
pushf ;must save C flag
mov [svebyt],al
shl BYTE [svebyt],1
shl BYTE [svebyt],1
shl BYTE [svebyt],1
shl BYTE [svebyt],1
and al,11110000b
mov ah,[es:Z80+bx]
and ah,00001111b
shr BYTE [es:Z80+bx],1
shr BYTE [es:Z80+bx],1
shr BYTE [es:Z80+bx],1
shr BYTE [es:Z80+bx],1
or al,ah
mov ah,[svebyt]
or BYTE [es:Z80+bx],ah
popf
mov BYTE [FlagN],0
inc al
dec al
lahf
and ah,11101111b
XinstB
end

View File

@@ -0,0 +1,736 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* Bit Set Group *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 10 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Changed all uses of 'Z80' map segment to 'es:Z80'
; - Added 'align=16' to all SEGMENT declarations. (nasm def is align=1)
;
; v1.00 - 29 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
SEGMENT Z80map public align=16
Z80:
SEGMENT .code public align=16
GLOBAL Z_SET0w, Z_SET1w, Z_SET2w, Z_SET3w, Z_SET4w, Z_SET5w, Z_SET6w, Z_SET7w
GLOBAL Z_SET0v, Z_SET1v, Z_SET2v, Z_SET3v, Z_SET4v, Z_SET5v, Z_SET6v, Z_SET7v
GLOBAL Z_SET0b, Z_SET0c, Z_SET0d, Z_SET0e, Z_SET0h, Z_SET0l, Z_SET0z, Z_SET0a
GLOBAL Z_SET1b, Z_SET1c, Z_SET1d, Z_SET1e, Z_SET1h, Z_SET1l, Z_SET1z, Z_SET1a
GLOBAL Z_SET2b, Z_SET2c, Z_SET2d, Z_SET2e, Z_SET2h, Z_SET2l, Z_SET2z, Z_SET2a
GLOBAL Z_SET3b, Z_SET3c, Z_SET3d, Z_SET3e, Z_SET3h, Z_SET3l, Z_SET3z, Z_SET3a
GLOBAL Z_SET4b, Z_SET4c, Z_SET4d, Z_SET4e, Z_SET4h, Z_SET4l, Z_SET4z, Z_SET4a
GLOBAL Z_SET5b, Z_SET5c, Z_SET5d, Z_SET5e, Z_SET5h, Z_SET5l, Z_SET5z, Z_SET5a
GLOBAL Z_SET6b, Z_SET6c, Z_SET6d, Z_SET6e, Z_SET6h, Z_SET6l, Z_SET6z, Z_SET6a
GLOBAL Z_SET7b, Z_SET7c, Z_SET7d, Z_SET7e, Z_SET7h, Z_SET7l, Z_SET7z, Z_SET7a
; declared in INSTHAND.ASM
EXTERN Z80IX, Z80IY
%include "macros.asm"
;***********************************************************
;* SET 0,B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET0b:
lahf
or ch,00000001b
XinstB
;***********************************************************
;* SET 1,B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET1b:
lahf
or ch,00000010b
XinstB
;***********************************************************
;* SET 2,B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET2b:
lahf
or ch,00000100b
XinstB
;***********************************************************
;* SET 3,B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET3b:
lahf
or ch,00001000b
XinstB
;***********************************************************
;* SET 4,B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET4b:
lahf
or ch,00010000b
XinstB
;***********************************************************
;* SET 5,B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET5b:
lahf
or ch,00100000b
XinstB
;***********************************************************
;* SET 6,B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET6b:
lahf
or ch,01000000b
XinstB
;***********************************************************
;* SET 7,B Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET7b:
lahf
or ch,10000000b
XinstB
;***********************************************************
;* SET 0,C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET0c:
lahf
or cl,00000001b
XinstB
;***********************************************************
;* SET 1,C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET1c:
lahf
or cl,00000010b
XinstB
;***********************************************************
;* SET 2,C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET2c:
lahf
or cl,00000100b
XinstB
;***********************************************************
;* SET 3,C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET3c:
lahf
or cl,00001000b
XinstB
;***********************************************************
;* SET 4,C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET4c:
lahf
or cl,00010000b
XinstB
;***********************************************************
;* SET 5,C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET5c:
lahf
or cl,00100000b
XinstB
;***********************************************************
;* SET 6,C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET6c:
lahf
or cl,01000000b
XinstB
;***********************************************************
;* SET 7,C Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET7c:
lahf
or cl,10000000b
XinstB
;***********************************************************
;* SET 0,D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET0d:
lahf
or dh,00000001b
XinstB
;***********************************************************
;* SET 1,D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET1d:
lahf
or dh,00000010b
XinstB
;***********************************************************
;* SET 2,D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET2d:
lahf
or dh,00000100b
XinstB
;***********************************************************
;* SET 3,D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET3d:
lahf
or dh,00001000b
XinstB
;***********************************************************
;* SET 4,D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET4d:
lahf
or dh,00010000b
XinstB
;***********************************************************
;* SET 5,D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET5d:
lahf
or dh,00100000b
XinstB
;***********************************************************
;* SET 6,D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET6d:
lahf
or dh,01000000b
XinstB
;***********************************************************
;* SET 7,D Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET7d:
lahf
or dh,10000000b
XinstB
;***********************************************************
;* SET 0,E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET0e:
lahf
or dl,00000001b
XinstB
;***********************************************************
;* SET 1,E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET1e:
lahf
or dl,00000010b
XinstB
;***********************************************************
;* SET 2,E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET2e:
lahf
or dl,00000100b
XinstB
;***********************************************************
;* SET 3,E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET3e:
lahf
or dl,00001000b
XinstB
;***********************************************************
;* SET 4,E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET4e:
lahf
or dl,00010000b
XinstB
;***********************************************************
;* SET 5,E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET5e:
lahf
or dl,00100000b
XinstB
;***********************************************************
;* SET 6,E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET6e:
lahf
or dl,01000000b
XinstB
;***********************************************************
;* SET 7,E Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET7e:
lahf
or dl,10000000b
XinstB
;***********************************************************
;* SET 0,H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET0h:
lahf
or bh,00000001b
XinstB
;***********************************************************
;* SET 1,H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET1h:
lahf
or bh,00000010b
XinstB
;***********************************************************
;* SET 2,H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET2h:
lahf
or bh,00000100b
XinstB
;***********************************************************
;* SET 3,H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET3h:
lahf
or bh,00001000b
XinstB
;***********************************************************
;* SET 4,H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET4h:
lahf
or bh,00010000b
XinstB
;***********************************************************
;* SET 5,H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET5h:
lahf
or bh,00100000b
XinstB
;***********************************************************
;* SET 6,H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET6h:
lahf
or bh,01000000b
XinstB
;***********************************************************
;* SET 7,H Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET7h:
lahf
or bh,10000000b
XinstB
;***********************************************************
;* SET 0,L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET0l:
lahf
or bl,00000001b
XinstB
;***********************************************************
;* SET 1,L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET1l:
lahf
or bl,00000010b
XinstB
;***********************************************************
;* SET 2,L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET2l:
lahf
or bl,00000100b
XinstB
;***********************************************************
;* SET 3,L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET3l:
lahf
or bl,00001000b
XinstB
;***********************************************************
;* SET 4,L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET4l:
lahf
or bl,00010000b
XinstB
;***********************************************************
;* SET 5,L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET5l:
lahf
or bl,00100000b
XinstB
;***********************************************************
;* SET 6,L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET6l:
lahf
or bl,01000000b
XinstB
;***********************************************************
;* SET 7,L Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET7l:
lahf
or bl,10000000b
XinstB
;***********************************************************
;* SET 0,A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET0a:
lahf
or al,00000001b
XinstB
;***********************************************************
;* SET 1,A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET1a:
lahf
or al,00000010b
XinstB
;***********************************************************
;* SET 2,A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET2a:
lahf
or al,00000100b
XinstB
;***********************************************************
;* SET 3,A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET3a:
lahf
or al,00001000b
XinstB
;***********************************************************
;* SET 4,A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET4a:
lahf
or al,00010000b
XinstB
;***********************************************************
;* SET 5,A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET5a:
lahf
or al,00100000b
XinstB
;***********************************************************
;* SET 6,A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET6a:
lahf
or al,01000000b
XinstB
;***********************************************************
;* SET 7,A Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET7a:
lahf
or al,10000000b
XinstB
;***********************************************************
;* SET 0,(HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET0z:
lahf
or BYTE [es:Z80+bx],00000001b
XinstB
;***********************************************************
;* SET 1,(HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET1z:
lahf
or BYTE [es:Z80+bx],00000010b
XinstB
;***********************************************************
;* SET 2,(HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET2z:
lahf
or BYTE [es:Z80+bx],00000100b
XinstB
;***********************************************************
;* SET 3,(HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET3z:
lahf
or BYTE [es:Z80+bx],00001000b
XinstB
;***********************************************************
;* SET 4,(HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET4z:
lahf
or BYTE [es:Z80+bx],00010000b
XinstB
;***********************************************************
;* SET 5,(HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET5z:
lahf
or BYTE [es:Z80+bx],00100000b
XinstB
;***********************************************************
;* SET 6,(HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET6z:
lahf
or BYTE [es:Z80+bx],01000000b
XinstB
;***********************************************************
;* SET 7,(HL) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET7z:
lahf
or BYTE [es:Z80+bx],10000000b
XinstB
;***********************************************************
;* SET 0,(IX+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;* SET 0,(IY+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET0w:
Z_SET0v:
lahf
or BYTE [es:Z80+si],00000001b
XinstB
;***********************************************************
;* SET 1,(IX+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;* SET 1,(IY+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET1w:
Z_SET1v:
lahf
or BYTE [es:Z80+si],00000010b
XinstB
;***********************************************************
;* SET 2,(IX+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;* SET 2,(IY+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET2w:
Z_SET2v:
lahf
or BYTE [es:Z80+si],00000100b
XinstB
;***********************************************************
;* SET 3,(IX+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;* SET 3,(IY+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET3w:
Z_SET3v:
lahf
or BYTE [es:Z80+si],00001000b
XinstB
;***********************************************************
;* SET 4,(IX+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;* SET 4,(IY+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET4w:
Z_SET4v:
lahf
or BYTE [es:Z80+si],00010000b
XinstB
;***********************************************************
;* SET 5,(IX+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;* SET 5,(IY+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET5w:
Z_SET5v:
lahf
or BYTE [es:Z80+si],00100000b
XinstB
;***********************************************************
;* SET 6,(IX+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;* SET 6,(IY+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET6w:
Z_SET6v:
lahf
or BYTE [es:Z80+si],01000000b
XinstB
;***********************************************************
;* SET 7,(IX+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;* SET 7,(IY+NN) Flags: S Z - H - P/V N C *
;* . . x . x . . . *
;***********************************************************
Z_SET7w:
Z_SET7v:
lahf
or BYTE [es:Z80+si],10000000b
XinstB
end

View File

@@ -0,0 +1,576 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* Z80 Opcodes and Function Interface tables *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 10 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Added 'align=16' to all SEGMENT declarations. (nasm def is align=1)
;
; v1.00 - 29 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
SEGMENT .code public align=16
GLOBAL T0, T1, T2, T3, T4, T5, T6, T7, Tx
; declared in FUNCTION.ASM
EXTERN trp0__, trp1__, fnc___
EXTERN GtBoot
EXTERN blkcnt, blkget, blkput, blkfil
EXTERN GtZseg, intfnc
EXTERN GetByt, SetByt
EXTERN prmsta, prmget, vidsta, vidset
EXTERN usrbyt, failed, rstz80, extemu
; declared in HARDWARE.ASM
EXTERN bnkuse, bnksel, bnkmve, bnkdta
EXTERN bnkdma
EXTERN kbd1in, kbd1st, kbd1ip
EXTERN kbd2in, kbd2st, kbd2ip
EXTERN lptini, lptsta, lptout
EXTERN comini, comist, cominp, comost
EXTERN comout
EXTERN gettme, settme, getdte, setdte
EXTERN rdflop, wrflop, rdhard, wrhard
EXTERN GtHard, FlHard
; declared in VIDEO.ASM
EXTERN crt1in, crt1st, crt1op
EXTERN crt2in, crt2st, crt2op
;$CB opcodes for IX
EXTERN Z_RLCw, Z_RRCw, Z_RLw, Z_RRw
EXTERN Z_SLAw, Z_SRAw, Z_SRLw
EXTERN Z_BIT0w, Z_BIT1w, Z_BIT2w, Z_BIT3w
EXTERN Z_BIT4w, Z_BIT5w, Z_BIT6w, Z_BIT7w
EXTERN Z_RES0w, Z_RES1w, Z_RES2w, Z_RES3w
EXTERN Z_RES4w, Z_RES5w, Z_RES6w, Z_RES7w
EXTERN Z_SET0w, Z_SET1w, Z_SET2w, Z_SET3w
EXTERN Z_SET4w, Z_SET5w, Z_SET6w, Z_SET7w
;$CB opcodes for IY
EXTERN Z_RLCv, Z_RRCv, Z_RLv, Z_RRv
EXTERN Z_SLAv, Z_SRAv, Z_SRLv
EXTERN Z_BIT0v, Z_BIT1v, Z_BIT2v, Z_BIT3v
EXTERN Z_BIT4v, Z_BIT5v, Z_BIT6v, Z_BIT7v
EXTERN Z_RES0v, Z_RES1v, Z_RES2v, Z_RES3v
EXTERN Z_RES4v, Z_RES5v, Z_RES6v, Z_RES7v
EXTERN Z_SET0v, Z_SET1v, Z_SET2v, Z_SET3v
EXTERN Z_SET4v, Z_SET5v, Z_SET6v, Z_SET7v
;1st opcode for IX
EXTERN Z_ADxbc, Z_ADxde, Z_LDxn, Z_LDmx
EXTERN Z_INCx, Z_ADxx, Z_LDxm, Z_DECx
EXTERN Z_INCw, Z_DECw, Z_LDwn, Z_ADxsp
EXTERN Z_LDbw, Z_LDcw, Z_LDdw, Z_LDew
EXTERN Z_LDhw, Z_LDlw, Z_LDwb, Z_LDwc
EXTERN Z_LDwd, Z_LDwe, Z_LDwh, Z_LDwl
EXTERN Z_LDwa, Z_LDaw, Z_ADDw, Z_ADCw
EXTERN Z_SUBw, Z_SBCw, Z_ANDw, Z_XORw
EXTERN Z_ORw, Z_CPw, CBxops, Z_POPx
EXTERN Z_EXspx, Z_PUSHx, Z_JPx, Z_LDspx
;1st opcode for IY
EXTERN Z_ADybc, Z_ADyde, Z_LDyn, Z_LDmy
EXTERN Z_INCy, Z_ADyy, Z_LDym, Z_DECy
EXTERN Z_INCv, Z_DECv, Z_LDvn, Z_ADysp
EXTERN Z_LDbv, Z_LDcv, Z_LDdv, Z_LDev
EXTERN Z_LDhv, Z_LDlv, Z_LDvb, Z_LDvc
EXTERN Z_LDvd, Z_LDve, Z_LDvh, Z_LDvl
EXTERN Z_LDva, Z_LDav, Z_ADDv, Z_ADCv
EXTERN Z_SUBv, Z_SBCv, Z_ANDv, Z_XORv
EXTERN Z_ORv, Z_CPv, CByops, Z_POPy
EXTERN Z_EXspy, Z_PUSHy, Z_JPy, Z_LDspy
;$ED Opcode Table
EXTERN Z_INbc, Z_OUTcb, Z_SChlbc,Z_LDmbc
EXTERN Z_NEG, Z_RETN, Z_IM0, Z_LDia
EXTERN Z_INcc, Z_OUTcc, Z_AChlbc,Z_LDbcm
EXTERN Z_RETI, Z_LDra, Z_INdc, Z_OUTcd
EXTERN Z_SChlde,Z_LDmde, Z_IM1, Z_LDai
EXTERN Z_INec, Z_OUTce, Z_AChlde,Z_LDdem
EXTERN Z_IM2, Z_LDar, Z_INhc, Z_OUTch
EXTERN Z_SChlhl,Z_RRD, Z_INlc, Z_OUTcl
EXTERN Z_AChlhl,Z_RLD, Z_INfc, Z_SChlsp
EXTERN Z_LDmsp, Z_INac, Z_OUTca, Z_AChlsp
EXTERN Z_LDspm, Z_LDI, Z_CPI, Z_INI
EXTERN Z_OUTI, Z_LDD, Z_CPD, Z_IND
EXTERN Z_OUTD, Z_LDIR, Z_CPIR, Z_INIR
EXTERN Z_OTIR, Z_LDDR, Z_CPDR, Z_INDR
EXTERN Z_OTDR
;$CB opcode table
EXTERN Z_RLCb, Z_RLCc, Z_RLCd, Z_RLCe
EXTERN Z_RLCh, Z_RLCl, Z_RLCz, Z_RLCa
EXTERN Z_RRCb, Z_RRCc, Z_RRCd, Z_RRCe
EXTERN Z_RRCh, Z_RRCl, Z_RRCz, Z_RRCa
EXTERN Z_RLb, Z_RLc, Z_RLd, Z_RLe
EXTERN Z_RLh, Z_RLl, Z_RLz, Z_RLa
EXTERN Z_RRb, Z_RRc, Z_RRd, Z_RRe
EXTERN Z_RRh, Z_RRl, Z_RRz, Z_RRa
EXTERN Z_SLAb, Z_SLAc, Z_SLAd, Z_SLAe
EXTERN Z_SLAh, Z_SLAl, Z_SLAz, Z_SLAa
EXTERN Z_SRAb, Z_SRAc, Z_SRAd, Z_SRAe
EXTERN Z_SRAh, Z_SRAl, Z_SRAz, Z_SRAa
EXTERN Z_SRLb, Z_SRLc, Z_SRLd, Z_SRLe
EXTERN Z_SRLh, Z_SRLl, Z_SRLz, Z_SRLa
EXTERN Z_BIT0b, Z_BIT0c, Z_BIT0d, Z_BIT0e
EXTERN Z_BIT0h, Z_BIT0l, Z_BIT0z, Z_BIT0a
EXTERN Z_BIT1b, Z_BIT1c, Z_BIT1d, Z_BIT1e
EXTERN Z_BIT1h, Z_BIT1l, Z_BIT1z, Z_BIT1a
EXTERN Z_BIT2b, Z_BIT2c, Z_BIT2d, Z_BIT2e
EXTERN Z_BIT2h, Z_BIT2l, Z_BIT2z, Z_BIT2a
EXTERN Z_BIT3b, Z_BIT3c, Z_BIT3d, Z_BIT3e
EXTERN Z_BIT3h, Z_BIT3l, Z_BIT3z, Z_BIT3a
EXTERN Z_BIT4b, Z_BIT4c, Z_BIT4d, Z_BIT4e
EXTERN Z_BIT4h, Z_BIT4l, Z_BIT4z, Z_BIT4a
EXTERN Z_BIT5b, Z_BIT5c, Z_BIT5d, Z_BIT5e
EXTERN Z_BIT5h, Z_BIT5l, Z_BIT5z, Z_BIT5a
EXTERN Z_BIT6b, Z_BIT6c, Z_BIT6d, Z_BIT6e
EXTERN Z_BIT6h, Z_BIT6l, Z_BIT6z, Z_BIT6a
EXTERN Z_BIT7b, Z_BIT7c, Z_BIT7d, Z_BIT7e
EXTERN Z_BIT7h, Z_BIT7l, Z_BIT7z, Z_BIT7a
EXTERN Z_RES0b, Z_RES0c, Z_RES0d, Z_RES0e
EXTERN Z_RES0h, Z_RES0l, Z_RES0z, Z_RES0a
EXTERN Z_RES1b, Z_RES1c, Z_RES1d, Z_RES1e
EXTERN Z_RES1h, Z_RES1l, Z_RES1z, Z_RES1a
EXTERN Z_RES2b, Z_RES2c, Z_RES2d, Z_RES2e
EXTERN Z_RES2h, Z_RES2l, Z_RES2z, Z_RES2a
EXTERN Z_RES3b, Z_RES3c, Z_RES3d, Z_RES3e
EXTERN Z_RES3h, Z_RES3l, Z_RES3z, Z_RES3a
EXTERN Z_RES4b, Z_RES4c, Z_RES4d, Z_RES4e
EXTERN Z_RES4h, Z_RES4l, Z_RES4z, Z_RES4a
EXTERN Z_RES5b, Z_RES5c, Z_RES5d, Z_RES5e
EXTERN Z_RES5h, Z_RES5l, Z_RES5z, Z_RES5a
EXTERN Z_RES6b, Z_RES6c, Z_RES6d, Z_RES6e
EXTERN Z_RES6h, Z_RES6l, Z_RES6z, Z_RES6a
EXTERN Z_RES7b, Z_RES7c, Z_RES7d, Z_RES7e
EXTERN Z_RES7h, Z_RES7l, Z_RES7z, Z_RES7a
EXTERN Z_SET0b, Z_SET0c, Z_SET0d, Z_SET0e
EXTERN Z_SET0h, Z_SET0l, Z_SET0z, Z_SET0a
EXTERN Z_SET1b, Z_SET1c, Z_SET1d, Z_SET1e
EXTERN Z_SET1h, Z_SET1l, Z_SET1z, Z_SET1a
EXTERN Z_SET2b, Z_SET2c, Z_SET2d, Z_SET2e
EXTERN Z_SET2h, Z_SET2l, Z_SET2z, Z_SET2a
EXTERN Z_SET3b, Z_SET3c, Z_SET3d, Z_SET3e
EXTERN Z_SET3h, Z_SET3l, Z_SET3z, Z_SET3a
EXTERN Z_SET4b, Z_SET4c, Z_SET4d, Z_SET4e
EXTERN Z_SET4h, Z_SET4l, Z_SET4z, Z_SET4a
EXTERN Z_SET5b, Z_SET5c, Z_SET5d, Z_SET5e
EXTERN Z_SET5h, Z_SET5l, Z_SET5z, Z_SET5a
EXTERN Z_SET6b, Z_SET6c, Z_SET6d, Z_SET6e
EXTERN Z_SET6h, Z_SET6l, Z_SET6z, Z_SET6a
EXTERN Z_SET7b, Z_SET7c, Z_SET7d, Z_SET7e
EXTERN Z_SET7h, Z_SET7l, Z_SET7z, Z_SET7a
;1st opcode
EXTERN Z_NOP, Z_LDbcn, Z_LDbca, Z_INCbc
EXTERN Z_INCb, Z_DECb, Z_LDbn, Z_RLCA
EXTERN Z_EXafaf,Z_ADhlbc,Z_LDabc, Z_DECbc
EXTERN Z_INCc, Z_DECc, Z_LDcn, Z_RRCA
EXTERN Z_DJNZ, Z_LDden, Z_LDdea, Z_INCde
EXTERN Z_INCd, Z_DECd, Z_LDdn, Z_RLA
EXTERN Z_JR, Z_ADhlde,Z_LDade, Z_DECde
EXTERN Z_INCe, Z_DECe, Z_LDen, Z_RRA
EXTERN Z_JRNZ, Z_LDhln, Z_LDmhl, Z_INChl
EXTERN Z_INCh, Z_DECh, Z_LDhn, Z_DAA
EXTERN Z_JRZ, Z_ADhlhl,Z_LDhlm, Z_DEChl
EXTERN Z_INCl, Z_DECl, Z_LDln, Z_CPL
EXTERN Z_JRNC, Z_LDspn, Z_LDma, Z_INCsp
EXTERN Z_INCz, Z_DECz, Z_LDzn, Z_SCF
EXTERN Z_JRC, Z_ADhlsp,Z_LDam, Z_DECsp
EXTERN Z_INCa, Z_DECa, Z_LDan, Z_CCF
EXTERN Z_LDbb, Z_LDbc, Z_LDbd, Z_LDbe
EXTERN Z_LDbh, Z_LDbl, Z_LDbz, Z_LDba
EXTERN Z_LDcb, Z_LDcc, Z_LDcd, Z_LDce
EXTERN Z_LDch, Z_LDcl, Z_LDcz, Z_LDca
EXTERN Z_LDdb, Z_LDdc, Z_LDdd, Z_LDde
EXTERN Z_LDdh, Z_LDdl, Z_LDdz, Z_LDda
EXTERN Z_LDeb, Z_LDec, Z_LDed, Z_LDee
EXTERN Z_LDeh, Z_LDel, Z_LDez, Z_LDea
EXTERN Z_LDhb, Z_LDhc, Z_LDhd, Z_LDhe
EXTERN Z_LDhh, Z_LDhl, Z_LDhz, Z_LDha
EXTERN Z_LDlb, Z_LDlc, Z_LDld, Z_LDle
EXTERN Z_LDlh, Z_LDll, Z_LDlz, Z_LDla
EXTERN Z_LDzb, Z_LDzc, Z_LDzd, Z_LDze
EXTERN Z_LDzh, Z_LDzl, Z_HALT, Z_LDza
EXTERN Z_LDab, Z_LDac, Z_LDad, Z_LDae
EXTERN Z_LDah, Z_LDal, Z_LDaz, Z_LDaa
EXTERN Z_ADDb, Z_ADDc, Z_ADDd, Z_ADDe
EXTERN Z_ADDh, Z_ADDl, Z_ADDz, Z_ADDa
EXTERN Z_ADCb, Z_ADCc, Z_ADCd, Z_ADCe
EXTERN Z_ADCh, Z_ADCl, Z_ADCz, Z_ADCa
EXTERN Z_SUBb, Z_SUBc, Z_SUBd, Z_SUBe
EXTERN Z_SUBh, Z_SUBl, Z_SUBz, Z_SUBa
EXTERN Z_SBCb, Z_SBCc, Z_SBCd, Z_SBCe
EXTERN Z_SBCh, Z_SBCl, Z_SBCz, Z_SBCa
EXTERN Z_ANDb, Z_ANDc, Z_ANDd, Z_ANDe
EXTERN Z_ANDh, Z_ANDl, Z_ANDz, Z_ANDa
EXTERN Z_XORb, Z_XORc, Z_XORd, Z_XORe
EXTERN Z_XORh, Z_XORl, Z_XORz, Z_XORa
EXTERN Z_ORb, Z_ORc, Z_ORd, Z_ORe
EXTERN Z_ORh, Z_ORl, Z_ORz, Z_ORa
EXTERN Z_CPb, Z_CPc, Z_CPd, Z_CPe
EXTERN Z_CPh, Z_CPl, Z_CPz, Z_CPa
EXTERN Z_RETNZ, Z_POPbc, Z_JPNZ, Z_JP
EXTERN Z_CALLNZ,Z_PUSHbc,Z_ADDn, Z_RST0
EXTERN Z_RETZ, Z_RET, Z_JPZ, CBops
EXTERN Z_CALLZ, Z_CALL, Z_ADCn, Z_RST1
EXTERN Z_RETNC, Z_POPde, Z_JPNC, Z_8086
EXTERN Z_CALLNC,Z_PUSHde,Z_SUBn, Z_RST2
EXTERN Z_RETC, Z_EXX, Z_JPC, Z_INan
EXTERN Z_CALLC, IXops, Z_SBCn, Z_RST3
EXTERN Z_RETPO, Z_POPhl, Z_JPPO, Z_EXsphl
EXTERN Z_CALLPO,Z_PUSHhl,Z_ANDn, Z_RST4
EXTERN Z_RETPE, Z_JPhl, Z_JPPE, Z_EXdehl
EXTERN Z_CALLPE,EDops, Z_XORn, Z_RST5
EXTERN Z_RETP, Z_POPaf, Z_JPP, Z_DI
EXTERN Z_CALLP, Z_PUSHaf,Z_ORn, Z_RST6
EXTERN Z_RETM, Z_LDsphl,Z_JPM, Z_EI
EXTERN Z_CALLM, IYops, Z_CPn, Z_RST7
; 8086 high level interface functions
T7 dw kbd1in, kbd1st, kbd1ip, fnc___, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw kbd2in, kbd2st, kbd2ip, fnc___, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw crt1in, crt1st, crt1op, fnc___, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw crt2in, crt2st, crt2op, fnc___, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw lptini, lptsta, lptout, fnc___, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw comini, comist, cominp, comost, comout, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw gettme, settme, getdte, setdte, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw rdflop, wrflop, rdhard, wrhard, GtBoot, GtHard, FlHard, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw blkcnt, blkget, blkput, blkfil, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw GtZseg, intfnc, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw GetByt, SetByt, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___, fnc___
dw bnkuse, bnksel, bnkmve, bnkdta, bnkdma, fnc___, fnc___, fnc___
dw prmsta, prmget, vidsta, vidset, usrbyt, failed, rstz80, extemu
; $CB opcodes for IX
;
T6 dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RLCw, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RRCw, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RLw, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RRw, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SLAw, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SRAw, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SRLw, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_BIT0w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_BIT1w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_BIT2w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_BIT3w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_BIT4w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_BIT5w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_BIT6w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_BIT7w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RES0w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RES1w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RES2w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RES3w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RES4w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RES5w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RES6w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RES7w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SET0w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SET1w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SET2w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SET3w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SET4w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SET5w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SET6w, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SET7w, trp0__
; $CB opcodes for IY
;
T5 dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RLCv, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RRCv, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RLv, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RRv, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SLAv, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SRAv, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SRLv, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_BIT0v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_BIT1v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_BIT2v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_BIT3v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_BIT4v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_BIT5v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_BIT6v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_BIT7v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RES0v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RES1v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RES2v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RES3v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RES4v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RES5v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RES6v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_RES7v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SET0v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SET1v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SET2v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SET3v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SET4v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SET5v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SET6v, trp0__
dw trp0__, trp0__, trp0__, trp0__, trp0__, trp0__, Z_SET7v, trp0__
; 1st opcode for IX
;
T4 dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, Z_ADxbc, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, Z_ADxde, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, Z_LDxn, Z_LDmx, Z_INCx, trp1__, trp1__, trp1__, trp1__
dw trp1__, Z_ADxx, Z_LDxm, Z_DECx, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, Z_INCw, Z_DECw, Z_LDwn, trp1__
dw trp1__, Z_ADxsp, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_LDbw, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_LDcw, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_LDdw, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_LDew, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_LDhw, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_LDlw, trp1__
dw Z_LDwb, Z_LDwc, Z_LDwd, Z_LDwe, Z_LDwh, Z_LDwl, trp1__, Z_LDwa
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_LDaw, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_ADDw, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_ADCw, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_SUBw, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_SBCw, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_ANDw, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_XORw, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_ORw, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_CPw, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, CBxops, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, Z_POPx, trp1__, Z_EXspx, trp1__, Z_PUSHx, trp1__, trp1__
dw trp1__, Z_JPx, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, Z_LDspx, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
; 1st opcode for IY
;
T3 dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, Z_ADybc, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, Z_ADyde, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, Z_LDyn, Z_LDmy, Z_INCy, trp1__, trp1__, trp1__, trp1__
dw trp1__, Z_ADyy, Z_LDym, Z_DECy, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, Z_INCv, Z_DECv, Z_LDvn, trp1__
dw trp1__, Z_ADysp, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_LDbv, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_LDcv, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_LDdv, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_LDev, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_LDhv, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_LDlv, trp1__
dw Z_LDvb, Z_LDvc, Z_LDvd, Z_LDve, Z_LDvh, Z_LDvl, trp1__, Z_LDva
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_LDav, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_ADDv, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_ADCv, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_SUBv, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_SBCv, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_ANDv, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_XORv, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_ORv, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, Z_CPv, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, CByops, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, Z_POPy, trp1__, Z_EXspy, trp1__, Z_PUSHy, trp1__, trp1__
dw trp1__, Z_JPy, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, Z_LDspy, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
; $ED Opcode Table
;
T2 dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw Z_INbc, Z_OUTcb, Z_SChlbc,Z_LDmbc, Z_NEG, Z_RETN, Z_IM0, Z_LDia
dw Z_INcc, Z_OUTcc, Z_AChlbc,Z_LDbcm, trp1__, Z_RETI, trp1__, Z_LDra
dw Z_INdc, Z_OUTcd, Z_SChlde,Z_LDmde, trp1__, trp1__, Z_IM1, Z_LDai
dw Z_INec, Z_OUTce, Z_AChlde,Z_LDdem, trp1__, trp1__, Z_IM2, Z_LDar
dw Z_INhc, Z_OUTch, Z_SChlhl,trp1__, trp1__, trp1__, trp1__, Z_RRD
dw Z_INlc, Z_OUTcl, Z_AChlhl,trp1__, trp1__, trp1__, trp1__, Z_RLD
dw Z_INfc, trp1__, Z_SChlsp,Z_LDmsp, trp1__, trp1__, trp1__, trp1__
dw Z_INac, Z_OUTca, Z_AChlsp,Z_LDspm, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw Z_LDI, Z_CPI, Z_INI, Z_OUTI, trp1__, trp1__, trp1__, trp1__
dw Z_LDD, Z_CPD, Z_IND, Z_OUTD, trp1__, trp1__, trp1__, trp1__
dw Z_LDIR, Z_CPIR, Z_INIR, Z_OTIR, trp1__, trp1__, trp1__, trp1__
dw Z_LDDR, Z_CPDR, Z_INDR, Z_OTDR, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
; $CB opcode table
;
T1 dw Z_RLCb, Z_RLCc, Z_RLCd, Z_RLCe, Z_RLCh, Z_RLCl, Z_RLCz, Z_RLCa
dw Z_RRCb, Z_RRCc, Z_RRCd, Z_RRCe, Z_RRCh, Z_RRCl, Z_RRCz, Z_RRCa
dw Z_RLb, Z_RLc, Z_RLd, Z_RLe, Z_RLh, Z_RLl, Z_RLz, Z_RLa
dw Z_RRb, Z_RRc, Z_RRd, Z_RRe, Z_RRh, Z_RRl, Z_RRz, Z_RRa
dw Z_SLAb, Z_SLAc, Z_SLAd, Z_SLAe, Z_SLAh, Z_SLAl, Z_SLAz, Z_SLAa
dw Z_SRAb, Z_SRAc, Z_SRAd, Z_SRAe, Z_SRAh, Z_SRAl, Z_SRAz, Z_SRAa
dw trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__, trp1__
dw Z_SRLb, Z_SRLc, Z_SRLd, Z_SRLe, Z_SRLh, Z_SRLl, Z_SRLz, Z_SRLa
dw Z_BIT0b, Z_BIT0c, Z_BIT0d, Z_BIT0e, Z_BIT0h, Z_BIT0l, Z_BIT0z, Z_BIT0a
dw Z_BIT1b, Z_BIT1c, Z_BIT1d, Z_BIT1e, Z_BIT1h, Z_BIT1l, Z_BIT1z, Z_BIT1a
dw Z_BIT2b, Z_BIT2c, Z_BIT2d, Z_BIT2e, Z_BIT2h, Z_BIT2l, Z_BIT2z, Z_BIT2a
dw Z_BIT3b, Z_BIT3c, Z_BIT3d, Z_BIT3e, Z_BIT3h, Z_BIT3l, Z_BIT3z, Z_BIT3a
dw Z_BIT4b, Z_BIT4c, Z_BIT4d, Z_BIT4e, Z_BIT4h, Z_BIT4l, Z_BIT4z, Z_BIT4a
dw Z_BIT5b, Z_BIT5c, Z_BIT5d, Z_BIT5e, Z_BIT5h, Z_BIT5l, Z_BIT5z, Z_BIT5a
dw Z_BIT6b, Z_BIT6c, Z_BIT6d, Z_BIT6e, Z_BIT6h, Z_BIT6l, Z_BIT6z, Z_BIT6a
dw Z_BIT7b, Z_BIT7c, Z_BIT7d, Z_BIT7e, Z_BIT7h, Z_BIT7l, Z_BIT7z, Z_BIT7a
dw Z_RES0b, Z_RES0c, Z_RES0d, Z_RES0e, Z_RES0h, Z_RES0l, Z_RES0z, Z_RES0a
dw Z_RES1b, Z_RES1c, Z_RES1d, Z_RES1e, Z_RES1h, Z_RES1l, Z_RES1z, Z_RES1a
dw Z_RES2b, Z_RES2c, Z_RES2d, Z_RES2e, Z_RES2h, Z_RES2l, Z_RES2z, Z_RES2a
dw Z_RES3b, Z_RES3c, Z_RES3d, Z_RES3e, Z_RES3h, Z_RES3l, Z_RES3z, Z_RES3a
dw Z_RES4b, Z_RES4c, Z_RES4d, Z_RES4e, Z_RES4h, Z_RES4l, Z_RES4z, Z_RES4a
dw Z_RES5b, Z_RES5c, Z_RES5d, Z_RES5e, Z_RES5h, Z_RES5l, Z_RES5z, Z_RES5a
dw Z_RES6b, Z_RES6c, Z_RES6d, Z_RES6e, Z_RES6h, Z_RES6l, Z_RES6z, Z_RES6a
dw Z_RES7b, Z_RES7c, Z_RES7d, Z_RES7e, Z_RES7h, Z_RES7l, Z_RES7z, Z_RES7a
dw Z_SET0b, Z_SET0c, Z_SET0d, Z_SET0e, Z_SET0h, Z_SET0l, Z_SET0z, Z_SET0a
dw Z_SET1b, Z_SET1c, Z_SET1d, Z_SET1e, Z_SET1h, Z_SET1l, Z_SET1z, Z_SET1a
dw Z_SET2b, Z_SET2c, Z_SET2d, Z_SET2e, Z_SET2h, Z_SET2l, Z_SET2z, Z_SET2a
dw Z_SET3b, Z_SET3c, Z_SET3d, Z_SET3e, Z_SET3h, Z_SET3l, Z_SET3z, Z_SET3a
dw Z_SET4b, Z_SET4c, Z_SET4d, Z_SET4e, Z_SET4h, Z_SET4l, Z_SET4z, Z_SET4a
dw Z_SET5b, Z_SET5c, Z_SET5d, Z_SET5e, Z_SET5h, Z_SET5l, Z_SET5z, Z_SET5a
dw Z_SET6b, Z_SET6c, Z_SET6d, Z_SET6e, Z_SET6h, Z_SET6l, Z_SET6z, Z_SET6a
dw Z_SET7b, Z_SET7c, Z_SET7d, Z_SET7e, Z_SET7h, Z_SET7l, Z_SET7z, Z_SET7a
; 1st opcode
;
T0 dw Z_NOP, Z_LDbcn, Z_LDbca, Z_INCbc, Z_INCb, Z_DECb, Z_LDbn, Z_RLCA
dw Z_EXafaf,Z_ADhlbc,Z_LDabc, Z_DECbc, Z_INCc, Z_DECc, Z_LDcn, Z_RRCA
dw Z_DJNZ, Z_LDden, Z_LDdea, Z_INCde, Z_INCd, Z_DECd, Z_LDdn, Z_RLA
dw Z_JR, Z_ADhlde,Z_LDade, Z_DECde, Z_INCe, Z_DECe, Z_LDen, Z_RRA
dw Z_JRNZ, Z_LDhln, Z_LDmhl, Z_INChl, Z_INCh, Z_DECh, Z_LDhn, Z_DAA
dw Z_JRZ, Z_ADhlhl,Z_LDhlm, Z_DEChl, Z_INCl, Z_DECl, Z_LDln, Z_CPL
dw Z_JRNC, Z_LDspn, Z_LDma, Z_INCsp, Z_INCz, Z_DECz, Z_LDzn, Z_SCF
dw Z_JRC, Z_ADhlsp,Z_LDam, Z_DECsp, Z_INCa, Z_DECa, Z_LDan, Z_CCF
dw Z_LDbb, Z_LDbc, Z_LDbd, Z_LDbe, Z_LDbh, Z_LDbl, Z_LDbz, Z_LDba
dw Z_LDcb, Z_LDcc, Z_LDcd, Z_LDce, Z_LDch, Z_LDcl, Z_LDcz, Z_LDca
dw Z_LDdb, Z_LDdc, Z_LDdd, Z_LDde, Z_LDdh, Z_LDdl, Z_LDdz, Z_LDda
dw Z_LDeb, Z_LDec, Z_LDed, Z_LDee, Z_LDeh, Z_LDel, Z_LDez, Z_LDea
dw Z_LDhb, Z_LDhc, Z_LDhd, Z_LDhe, Z_LDhh, Z_LDhl, Z_LDhz, Z_LDha
dw Z_LDlb, Z_LDlc, Z_LDld, Z_LDle, Z_LDlh, Z_LDll, Z_LDlz, Z_LDla
dw Z_LDzb, Z_LDzc, Z_LDzd, Z_LDze, Z_LDzh, Z_LDzl, Z_HALT, Z_LDza
dw Z_LDab, Z_LDac, Z_LDad, Z_LDae, Z_LDah, Z_LDal, Z_LDaz, Z_LDaa
dw Z_ADDb, Z_ADDc, Z_ADDd, Z_ADDe, Z_ADDh, Z_ADDl, Z_ADDz, Z_ADDa
dw Z_ADCb, Z_ADCc, Z_ADCd, Z_ADCe, Z_ADCh, Z_ADCl, Z_ADCz, Z_ADCa
dw Z_SUBb, Z_SUBc, Z_SUBd, Z_SUBe, Z_SUBh, Z_SUBl, Z_SUBz, Z_SUBa
dw Z_SBCb, Z_SBCc, Z_SBCd, Z_SBCe, Z_SBCh, Z_SBCl, Z_SBCz, Z_SBCa
dw Z_ANDb, Z_ANDc, Z_ANDd, Z_ANDe, Z_ANDh, Z_ANDl, Z_ANDz, Z_ANDa
dw Z_XORb, Z_XORc, Z_XORd, Z_XORe, Z_XORh, Z_XORl, Z_XORz, Z_XORa
dw Z_ORb, Z_ORc, Z_ORd, Z_ORe, Z_ORh, Z_ORl, Z_ORz, Z_ORa
dw Z_CPb, Z_CPc, Z_CPd, Z_CPe, Z_CPh, Z_CPl, Z_CPz, Z_CPa
dw Z_RETNZ, Z_POPbc, Z_JPNZ, Z_JP, Z_CALLNZ,Z_PUSHbc,Z_ADDn, Z_RST0
dw Z_RETZ, Z_RET, Z_JPZ, CBops, Z_CALLZ, Z_CALL, Z_ADCn, Z_RST1
dw Z_RETNC, Z_POPde, Z_JPNC, Z_8086, Z_CALLNC,Z_PUSHde,Z_SUBn, Z_RST2
dw Z_RETC, Z_EXX, Z_JPC, Z_INan, Z_CALLC, IXops, Z_SBCn, Z_RST3
dw Z_RETPO, Z_POPhl, Z_JPPO, Z_EXsphl,Z_CALLPO,Z_PUSHhl,Z_ANDn, Z_RST4
dw Z_RETPE, Z_JPhl, Z_JPPE, Z_EXdehl,Z_CALLPE,EDops, Z_XORn, Z_RST5
dw Z_RETP, Z_POPaf, Z_JPP, Z_DI, Z_CALLP, Z_PUSHaf,Z_ORn, Z_RST6
dw Z_RETM, Z_LDsphl,Z_JPM, Z_EI, Z_CALLM, IYops, Z_CPn, Z_RST7
; 1st opcode table, COPY OF T0
;
Tx dw Z_NOP, Z_LDbcn, Z_LDbca, Z_INCbc, Z_INCb, Z_DECb, Z_LDbn, Z_RLCA
dw Z_EXafaf,Z_ADhlbc,Z_LDabc, Z_DECbc, Z_INCc, Z_DECc, Z_LDcn, Z_RRCA
dw Z_DJNZ, Z_LDden, Z_LDdea, Z_INCde, Z_INCd, Z_DECd, Z_LDdn, Z_RLA
dw Z_JR, Z_ADhlde,Z_LDade, Z_DECde, Z_INCe, Z_DECe, Z_LDen, Z_RRA
dw Z_JRNZ, Z_LDhln, Z_LDmhl, Z_INChl, Z_INCh, Z_DECh, Z_LDhn, Z_DAA
dw Z_JRZ, Z_ADhlhl,Z_LDhlm, Z_DEChl, Z_INCl, Z_DECl, Z_LDln, Z_CPL
dw Z_JRNC, Z_LDspn, Z_LDma, Z_INCsp, Z_INCz, Z_DECz, Z_LDzn, Z_SCF
dw Z_JRC, Z_ADhlsp,Z_LDam, Z_DECsp, Z_INCa, Z_DECa, Z_LDan, Z_CCF
dw Z_LDbb, Z_LDbc, Z_LDbd, Z_LDbe, Z_LDbh, Z_LDbl, Z_LDbz, Z_LDba
dw Z_LDcb, Z_LDcc, Z_LDcd, Z_LDce, Z_LDch, Z_LDcl, Z_LDcz, Z_LDca
dw Z_LDdb, Z_LDdc, Z_LDdd, Z_LDde, Z_LDdh, Z_LDdl, Z_LDdz, Z_LDda
dw Z_LDeb, Z_LDec, Z_LDed, Z_LDee, Z_LDeh, Z_LDel, Z_LDez, Z_LDea
dw Z_LDhb, Z_LDhc, Z_LDhd, Z_LDhe, Z_LDhh, Z_LDhl, Z_LDhz, Z_LDha
dw Z_LDlb, Z_LDlc, Z_LDld, Z_LDle, Z_LDlh, Z_LDll, Z_LDlz, Z_LDla
dw Z_LDzb, Z_LDzc, Z_LDzd, Z_LDze, Z_LDzh, Z_LDzl, Z_HALT, Z_LDza
dw Z_LDab, Z_LDac, Z_LDad, Z_LDae, Z_LDah, Z_LDal, Z_LDaz, Z_LDaa
dw Z_ADDb, Z_ADDc, Z_ADDd, Z_ADDe, Z_ADDh, Z_ADDl, Z_ADDz, Z_ADDa
dw Z_ADCb, Z_ADCc, Z_ADCd, Z_ADCe, Z_ADCh, Z_ADCl, Z_ADCz, Z_ADCa
dw Z_SUBb, Z_SUBc, Z_SUBd, Z_SUBe, Z_SUBh, Z_SUBl, Z_SUBz, Z_SUBa
dw Z_SBCb, Z_SBCc, Z_SBCd, Z_SBCe, Z_SBCh, Z_SBCl, Z_SBCz, Z_SBCa
dw Z_ANDb, Z_ANDc, Z_ANDd, Z_ANDe, Z_ANDh, Z_ANDl, Z_ANDz, Z_ANDa
dw Z_XORb, Z_XORc, Z_XORd, Z_XORe, Z_XORh, Z_XORl, Z_XORz, Z_XORa
dw Z_ORb, Z_ORc, Z_ORd, Z_ORe, Z_ORh, Z_ORl, Z_ORz, Z_ORa
dw Z_CPb, Z_CPc, Z_CPd, Z_CPe, Z_CPh, Z_CPl, Z_CPz, Z_CPa
dw Z_RETNZ, Z_POPbc, Z_JPNZ, Z_JP, Z_CALLNZ,Z_PUSHbc,Z_ADDn, Z_RST0
dw Z_RETZ, Z_RET, Z_JPZ, CBops, Z_CALLZ, Z_CALL, Z_ADCn, Z_RST1
dw Z_RETNC, Z_POPde, Z_JPNC, Z_8086, Z_CALLNC,Z_PUSHde,Z_SUBn, Z_RST2
dw Z_RETC, Z_EXX, Z_JPC, Z_INan, Z_CALLC, IXops, Z_SBCn, Z_RST3
dw Z_RETPO, Z_POPhl, Z_JPPO, Z_EXsphl,Z_CALLPO,Z_PUSHhl,Z_ANDn, Z_RST4
dw Z_RETPE, Z_JPhl, Z_JPPE, Z_EXdehl,Z_CALLPE,EDops, Z_XORn, Z_RST5
dw Z_RETP, Z_POPaf, Z_JPP, Z_DI, Z_CALLP, Z_PUSHaf,Z_ORn, Z_RST6
dw Z_RETM, Z_LDsphl,Z_JPM, Z_EI, Z_CALLM, IYops, Z_CPn, Z_RST7
end

View File

@@ -0,0 +1,388 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* Video function support for Z80 system code *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
; Televideo 920/ADM-3A Video Terminal, DOS video service
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 10 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Added 'align=16' to all SEGMENT declarations. (nasm def is align=1)
;
; v1.00 - 29 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
SEGMENT .code public align=16
GLOBAL crt1in, crt1st, crt1op
GLOBAL crt2in, crt2st, crt2op
; declared in MAIN.ASM
EXTERN vidoff
%include "macros.asm"
;
;===============================================================================
; CRT #2 Video functions (STDOUT): Initialize, Status, Output
; crt2in:-
; crt2st:- Return: STDOUT status in reg A
; crt2op:- Pass: STDOUT character in reg C
;===============================================================================
crt2in: retn
crt2st: mov al,0ffh ;output always ready
retn
crt2op: cmp BYTE [vidoff],0 ;is video turned off ?
jz crt2o
retn
crt2o: mov ah,002h ;character output function
mov dl,cl ;character to reg DL
int 021h
retn
;===============================================================================
; CRT #1 Video functions: Initialize, Status, Output
; crt1in:-
; crt1st:- Return: status in reg A
; crt1op:- Pass: character in reg C
;===============================================================================
; Initialize CRT output driver
crt1in: mov BYTE [atrbyt],00000111b ;set video atributes to use
mov BYTE [atrflg],00000000b
mov BYTE [esccnt],0
mov cl,26
jmp crt1op ;clear screen
;
; Return CRT status in Z80 reg A
crt1st: mov al,0ffh ;return CRT always ready
retn
;
; Send character in Z80 reg C to CRT
crt1op: cmp BYTE [vidoff],0 ;is video turned off ?
jz crt1o
retn
crt1o: cmp BYTE [esccnt],0 ;any escape codes expected ?
jnz esccde
cmp cl,' ' ;control or printable character ?
jnc print0
xor ch,ch
mov di,cx
shl di,1
jmp WORD [ctltbl+di] ;jump to control character handler
;
setesc: mov BYTE [esccnt],1
retn
esccde: inc BYTE [esccnt]
cmp BYTE [esccnt],2
jnz escact
mov [escchr],cl ;save the 1st escape character
escact: mov al,[escchr]
xor ah,ah
mov di,ax
shl di,1
jmp WORD [esctbl+di] ;jump to escape sequence handler
;
esc___: mov BYTE [esccnt],0 ;unsupported escape codes here
jmp crt1op ;print the character
;
ctl___: retn ;unsupported control codes here
;
print0: mov ah,009h ;write char and attribute function
mov al,' '
mov bh,000h ;page #0
mov bl,[atrbyt] ;attribute value
mov dl,cl ;save the character to display
mov cx,1 ;write 1 character
int 010h
mov cl,dl ;restore the character to display
print1: mov ah,00eh ;write TTY function
mov al,cl ;character to AL
mov bh,000h ;page #0
int 010h
retn
;
hghint: mov BYTE [esccnt],0 ;no more escape codes follow
test BYTE [atrflg],00000100b ;is reverse video on ?
jnz inten1
test BYTE [atrflg],00000001b ;is underline on ?
mov ah,00001001b
jnz inten0
mov ah,00001111b
inten0: and BYTE [atrbyt],10000000b
or [atrbyt],ah
inten1: or BYTE [atrflg],00000010b ;set high intensity flag on
retn
;
lowint: mov BYTE [esccnt],0 ;no more escape codes follow
test BYTE [atrflg],00000100b ;is reverse video on ?
jnz inten3
test BYTE [atrflg],00000001b ;is underline on ?
mov ah,00000001b
jnz inten2
mov ah,00000111b
inten2: and BYTE [atrbyt],10000000b
or [atrbyt],ah
inten3: and BYTE [atrflg],11111101b ;set high intensity flag off
retn
;
blnkon: mov BYTE [esccnt],0 ;no more escape codes follow
or BYTE [atrbyt],10000000b
retn
;
blnkof: mov BYTE [esccnt],0 ;no more escape codes follow
and BYTE [atrbyt],01111111b
retn
;
rvseon: mov BYTE [esccnt],0 ;no more escape codes follow
or BYTE [atrflg],00000100b ;set reverse flag on
and BYTE [atrbyt],10000000b
or BYTE [atrbyt],01110000b
retn
;
rvseof: mov BYTE [esccnt],0 ;no more escape codes follow
and BYTE [atrflg],11111011b ;set reverse flag off
test BYTE [atrflg],00000010b ;set low or high intensity ?
jz lowint
jmp hghint
;
undron: mov BYTE [esccnt],0 ;no more escape codes follow
test BYTE [atrflg],00000100b
jnz under1
test BYTE [atrbyt],00001000b
mov ah,00001001b
jnz under0
mov ah,00000001b
under0: and BYTE [atrbyt],10000000b
or [atrbyt],ah
under1: or BYTE [atrflg],00000001b ;set underline flag on
retn
;
undrof: mov BYTE [esccnt],0 ;no more escape codes follow
test BYTE [atrflg],00000100b
jnz under3
test BYTE [atrbyt],00001000b
mov ah,00001111b
jnz under2
mov ah,00000111b
under2: and BYTE [atrbyt],11110000b
or [atrbyt],ah
under3: and BYTE [atrflg],11111110b ;set underline flag off
retn
;
setcur: cmp BYTE [esccnt],2
jnz stcur0
retn
stcur0: cmp BYTE [esccnt],3
jnz stcur1
mov [escdta],cl ;save Y cursor position
extcur: retn
stcur1: mov BYTE [esccnt],0 ;no more escape codes follow
mov dh,[escdta]
sub dh,' ' ;adjust (Y = 0 for 1st line)
cmp dh,25 ;is Y in range ?
jnc extcur
mov dl,cl
sub dl,' ' ;adjust (X = 0 for 1st column)
cmp dl,80 ;is X in range ?
jnc extcur
jmp cursor
;
clreos: mov BYTE [esccnt],0 ;no more escape codes follow
mov ah,003h ;read cursor position function
mov bh,000h ;page #0
int 010h
cmp dh,25
jc clesc0
retn
clesc0: cmp dl,80
jc clesc1
retn
clesc1: mov al,80
mul dh
mov dh,0
add ax,dx
mov cx,2000
sub cx,ax ;number of characters to clear
jmp scrclr
;
clreol: mov BYTE [esccnt],0 ;no more escape codes follow
mov ah,003h ;read cursor position function
mov bh,000h ;page #0
int 010h
cmp dl,80
jc clrlne
retn
clrlne: mov cx,80
mov dh,0
sub cx,dx ;number of characters to clear
scrclr: mov ah,009h ;write char and attribute function
mov al,' '
mov bh,000h ;page #0
mov bl,007h ;attribute value
int 010h
retn
;
lneins: mov BYTE [esccnt],0 ;no more escape codes follow
mov ah,003h ;read cursor position function
mov bh,000h ;page #0
int 010h
mov ch,dh
mov cl,0
mov dh,24
mov dl,79
mov ah,007h ;scroll page down function
mov al,1 ;lines to blank
mov bh,07h ;attribute for blank
int 010h
retn
;
lnedel: mov BYTE [esccnt],0 ;no more escape codes follow
mov ah,003h ;read cursor position function
mov bh,000h ;page #0
int 010h
mov ch,dh
mov cl,0
mov dh,24
mov dl,79
mov ah,006h ;scroll page up function
mov al,1 ;lines to blank
mov bh,07h ;attribute for blank
int 010h
retn
;
clrscr: mov BYTE [esccnt],0 ;no more escape codes follow
mov ah,005h ;select active page for func #6, #7
mov al,0 ;page #0
int 010h
mov cx,0 ;top X and Y co-ordinates
mov dh,24 ;bottom Y co-ordinate
mov dl,79 ;bottom X co-ordinate
mov ah,006h ;scroll page up function
mov al,0 ;clear entire display
mov bh,07h ;attribute for blank
int 010h ;fall through to home cursor
;
hmecur: mov dx,0000h ;set cursor to 0, 0
cursor: mov ah,002h
mov bh,000h
int 010h
retn
;
vertab: mov ah,003h ;read cursor position function
mov bh,000h ;page #0
int 010h
cmp dh,0 ;is cursor Y on 1st line ?
jnz moveup
retn
moveup: dec dh ;decrement cursor Y
jmp cursor ;and set cursor
;
hortab: mov ah,003h ;read cursor position function
mov bh,000h ;page #0
int 010h
and dl,7
neg dl
add dl,8
nxtspc: mov ah,009h ;write char and attribute function
mov al,' '
mov bh,000h ;page #0
mov bl,[atrbyt] ;attribute value
mov cx,1 ;write 1 character
int 010h
mov ah,00eh ;write TTY function
mov al,' '
mov bh,000h ;page #0
int 010h
dec dl ;decrement tab counter
jnz nxtspc
retn
;
curfwd: mov ah,003h ;read cursor position function
mov bh,000h ;page #0
int 010h
cmp dl,79
jnc newlne
inc dl ;increment cursor X
jmp cursor ;and set cursor
newlne: mov dl,0 ;set cursor X to zero
mov ah,002h
mov bh,000h
int 010h
mov cl,00ah ;line feed character
jmp crt1op ;print it
;
esccnt db 0
escchr db 0
escdta db 0
atrbyt db 00000111b
atrflg db 00000000b
;
ctltbl dw ctl___, ctl___, ctl___, ctl___, ctl___, ctl___, ctl___, print1
dw print1, hortab, print1, vertab, curfwd, print1, ctl___, ctl___
dw ctl___, rvseof, ctl___, ctl___, ctl___, ctl___, ctl___, ctl___
dw ctl___, rvseon, clrscr, setesc, ctl___, ctl___, hmecur, ctl___
;
esctbl dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw lowint, hghint, clrscr, clrscr, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, setcur, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, lneins, esc___, esc___
dw esc___, esc___, rvseon, rvseof, undron, undrof, esc___, esc___
dw esc___, blnkof, lnedel, esc___, clreol, esc___, esc___, esc___
dw esc___, clreos, esc___, esc___, esc___, esc___, blnkon, esc___
dw esc___, esc___, esc___, esc___, esc___, lneins, esc___, esc___
dw esc___, esc___, rvseon, rvseof, undron, undrof, esc___, esc___
dw esc___, blnkof, lnedel, esc___, clreol, esc___, esc___, esc___
dw esc___, clreos, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
dw esc___, esc___, esc___, esc___, esc___, esc___, esc___, esc___
;
end

View File

@@ -0,0 +1,458 @@
;*******************************************************************************
;* z80em86 *
;* A Z80 CPU emulator coded in Intel 86 assembly language *
;* *
;* Window and Screen Output support for error messages *
;* *
;* Copyright (C) 1992-2009 Stewart Kay *
;*******************************************************************************
;
;===============================================================================
; ChangeLog (most recent entries are at top)
;===============================================================================
; v1.0.0 - 10 February 2009, S.J.Kay
; - Convert sources from TASM to NASM format and prepare for GPL release.
; - Added 'align=16' to all SEGMENT declarations. (nasm def is align=1)
;
; v1.00 - 29 April 1995 S.J.Kay
; - Last time code was worked on before releasing under the GPL.
;
; v0.00 - 1992 S.J.Kay
; - Started to code the Z80 emulator.
;===============================================================================
; z80em86 - A Z80 CPU emulator coded in Intel 86 assembly language.
; Copyright (C) 1992-2009 Stewart Kay
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;===============================================================================
SEGMENT .code public align=16
GLOBAL OpnWnd, ClsWnd
GLOBAL PrnByt, PrnHex, PrnStr, PrnChr, EraScr, HdeCur
GLOBAL GetAct, GetKey
; declared in MAIN.ASM
EXTERN VidSeg, VidBuf, prmflg
%include "macros.asm"
;===============================================================================
; Window box
; Pass: dh=window Y start
; dl=window X start
; ch=window Y finish
; cl=window X finish
; Return: nothing
;===============================================================================
OpnWnd: pushf
push ax
push bx
push si
push di
mov al,[WndNmb]
cmp al,4
jnz setwnd
jmp wndful
setwnd: push cx
push dx
xor ah,ah
mov di,ax
shl di,1
mov ah,003h ;read cursor position function
mov bh,000h ;page #0
int 010h
mov WORD [SveCur+di],dx ;save current cursor position
mov cx,4000
mov al,[WndNmb]
xor ah,ah
mul cx
mov di,ax
xor si,si
push ds
push es
mov es,[VidBuf]
mov ds,[VidSeg]
cld
rep movsb
pop es
pop ds
pop dx
pop cx
inc BYTE [WndNmb]
call WndBox
wndful: pop di
pop si
pop bx
pop ax
popf
retn
;===============================================================================
; Window close
; Pass: nothing
; Return: nothing
;===============================================================================
ClsWnd: pushf
push ax
push bx
push cx
push dx
push si
push di
mov al,[WndNmb]
or al,al
jnz reswnd
jmp notwnd
reswnd: dec al
mov [WndNmb],al
xor ah,ah
mov di,ax
shl di,1
mov dx,[SveCur+di] ;get cursor position
mov ah,002h ;set cursor function
mov bh,000h ;page #0
int 010h
mov cx,4000
mov al,[WndNmb]
xor ah,ah
mul cx
mov si,ax
xor di,di
push ds
push es
mov es,[VidSeg]
mov ds,[VidBuf]
cld
rep movsb
pop es
pop ds
notwnd: pop di
pop si
pop dx
pop cx
pop bx
pop ax
popf
retn
WndBox: pushf
push ax
push bx
mov [WndX0],dl
mov [WndY0],dh
mov [WndX1],cl
mov [WndY1],ch
sub ch,dh
dec ch
mov [BoxDep],ch
sub cl,dl
dec cl
mov [BoxWid],cl
mov ah,002h ;set cursor function
mov bh,000h ;page #0
int 010h
mov BYTE [BoxCh0],201
mov BYTE [BoxCh1],205
mov BYTE [BoxCh2],187
call DrwBox
mov ch,[BoxDep]
or ch,ch
jz BoxBot
mov BYTE [BoxCh0],186
mov BYTE [BoxCh1],' '
mov BYTE [BoxCh2],186
BoxDwn: call DrwBox
dec ch
jnz BoxDwn
BoxBot: mov BYTE [BoxCh0],200
mov BYTE [BoxCh1],205
mov BYTE [BoxCh2],188
call DrwBox
mov dl,[WndX0] ;top X position of window
add dl,2 ;start text 2 positions in
mov dh,[WndY0] ;top Y position of window
inc dh ;start text on next line
mov ah,002h ;set cursor function
int 010h
pop bx
pop ax
popf
retn
DrwBox: push cx
mov ah,009h ;write char and attribute function
mov bh,000h ;page #0
mov bl,070h ;attribute value
mov al,[BoxCh0]
mov cx,1 ;write 1 character
int 010h
mov ah,003h ;read cursor position function
inc dl
mov ah,002h ;set cursor function
int 010h
mov ah,009h ;write char and attribute function
mov al,[BoxCh1]
xor ch,ch ;write ? characters
mov cl,[BoxWid]
int 010h
add dl,cl
mov ah,002h ;set cursor function
int 010h
mov ah,009h ;write char and attribute function
mov al,[BoxCh2]
mov cx,1 ;write 1 character
int 010h
mov dl,[WndX0]
inc dh ;draw window on next line
mov ah,002h ;set cursor function
int 010h
pop cx
retn
;===============================================================================
; Print string
; Pass:
; Return: nothing
;===============================================================================
PrnStr: pushf
push ax
push si
PrnLp: mov al,[si]
inc si
cmp al,'$'
jz PrnExt
call PrnChr
jmp PrnLp
PrnExt: pop si
pop ax
popf
retn
;===============================================================================
; Print byte
; Pass:
; Return: nothing
;===============================================================================
PrnByt: pushf
push ax
push bx
mov bl,100
xor ah,ah
div bl
or al,al
jz PrnBy1
add al,'0'
call PrnChr ;print hundreds digit
PrnBy1: mov al,ah ;remainder
mov bl,10
xor ah,ah
div bl
or al,al
jz PrnBy2
add al,'0'
call PrnChr ;print tens digits
PrnBy2: mov al,ah ;remainder
add al,'0'
call PrnChr ;print units
pop bx
pop ax
popf
retn
;===============================================================================
; Print hex
; Pass:
; Return: nothing
;===============================================================================
PrnHex: pushf
push ax
push cx
mov ch,al
mov cl,4
shr al,cl
add al,'0'
cmp al,':'
jc Hex0
add al,007h
Hex0: call PrnChr
mov al,ch
and al,00fh
add al,'0'
cmp al,':'
jc Hex1
add al,007h
Hex1: call PrnChr
pop cx
pop ax
popf
retn
PrnChr: pushf
push ax
push bx
push cx
push dx
mov bh,000h ;page #0
mov dl,al ;save the character to display
cmp al,' '
jc PrnCh1
mov ah,009h ;write char and attribute function
mov bl,070h ;attribute value
mov cx,1 ;write 1 character
int 010h
PrnCh1: mov al,dl ;restore the character to display
cmp al,00dh
jz PrnCh2
cmp al,00ah
jz PrnCh3
mov ah,00eh ;write TTY function
jmp PrnCh4
PrnCh2: mov ah,003h ;read cursor position function
int 010h
mov dl,[WndX0]
add dl,2
mov ah,002h ;set cursor function
jmp PrnCh4
PrnCh3: mov ah,003h ;read cursor position function
int 010h
inc dh
mov ah,002h ;set cursor function
PrnCh4: int 010h
pop dx
pop cx
pop bx
pop ax
popf
retn
;===============================================================================
; Erase screen
; Pass:
; Return: nothing
;===============================================================================
EraScr: pushf
cmp BYTE [prmflg],0ffh
jz skpcls ;skip CLS if command tail
push ax
push bx
push cx
mov ah,005h ;select active page for func #6, #7
xor al,al ;page #0
int 010h
xor cx,cx ;top X and Y co-ordinates
mov dh,24 ;bottom Y co-ordinate
mov dl,79 ;bottom X co-ordinate
mov ah,006h ;scroll page up function
xor al,al ;entire display cleared if 0
mov bh,007h ;attribute for blank
int 010h ;fall through to home cursor
xor dx,dx ;set cursor to 0, 0
mov ah,002h
xor bh,bh ;page #0
int 010h
pop cx
pop bx
pop ax
skpcls: popf
retn
;===============================================================================
; Hide cursor
; Pass: nothing
; Return: nothing
;===============================================================================
HdeCur: push ax
push bx
push dx
mov dx,0ffffh ;cursor position
mov ah,002h ;set cursor function
mov bh,000h ;page #0
int 010h
pop dx
pop bx
pop ax
retn
;===============================================================================
; Get user key action
; Pass: nothing
; Return: AL=requested action
;===============================================================================
GetAct: call GetKey ;return key in reg AL
push ax ;save key pressed
call PrnChr ;print user's selection
GetRet: call keyinp
cmp al,008h
jnz notbck
call PrnChr
mov al,' '
call PrnChr
mov al,008h
call PrnChr
pop ax ;dump key
jmp GetAct ;retry again for another key
notbck: cmp al,00dh ;ENTER key pressed ?
jnz GetRet
pop ax
and al,11011111b ;convert to upper case
retn
;===============================================================================
; Get user key action
; Pass:
; Return: al=key
;===============================================================================
GetKey: push dx ;returns key in reg AL
nxttry: call keyinp
push si
mov dl,al
and dl,11011111b ;convert to upper case
nxtkey: cmp byte[si],dl
jz gotkey
inc si
cmp byte[si],'$'
jnz nxtkey
pop si
jmp nxttry
gotkey: pop si
pop dx
retn
keyinp: mov ah,001h ;get keyboard status function
int 016h
jz empbuf
mov ah,000h ;read key from keybaud function
int 016h
jmp keyinp ;empty keyboard buffer
empbuf: mov ah,000h ;read key from keybaud function
int 016h
retn ;keyboard key in AL
SveCur resw 4
WndNmb db 0
WndX0 resb 1
WndY0 resb 1
WndX1 resb 1
WndY1 resb 1
BoxCh0 resb 1
BoxCh1 resb 1
BoxCh2 resb 1
BoxDep resb 1
BoxWid resb 1
end

View File

@@ -0,0 +1,78 @@
(*************************************************************************)
(* *)
(* Z80 Hard Disk v1.00 *)
(* (C) Copyright S.J.Kay 6th December 1993 *)
(* *)
(* Creates a disk file to be used by the Z80 Emulator *)
(* program as a hard disk. *)
(* *)
(*************************************************************************)
uses
crt, dos;
const
HDDMEG = 4; { size of HDD file in Mbytes }
SECSZE = 512;
SECTRK = 64;
HDDSEC = (HDDMEG * 1024) * (1024 div SECSZE);
FLENME = 'Z80HDD.DSK';
MkeDrv : boolean = true;
var
F : file;
i : integer;
Sector : array [0..SECSZE-1] of byte;
DrvPth : string[80];
ChkUsr : string[1];
begin
clrscr;
writeln;
writeln('===================================================');
writeln('Z80 Hard Disk v1.00 (C) Copyright S.J.Kay 6/12/93');
writeln;
writeln('Creates a disk file to be used by the Z80 Emulator');
writeln(' program as a hard disk');
writeln('===================================================');
writeln;
writeln('Hard disk size: ', HDDMEG, ' Megabytes');
writeln;
write('Enter drive path: ');
readln(DrvPth);
writeln;
if (DrvPth <> '') and (not(DrvPth[length(DrvPth)] in [':', '\'])) then
DrvPth := DrvPth + '\';
assign(F, DrvPth + FLENME);
Setfattr(F, 0); { make file read/write }
{$I-}
reset(F);
if ioresult = 0 then
begin
close(F);
{$I+}
writeln('WARNING - ', DrvPth + FLENME, ' will be lost forever');
write( 'Do you wish to continue (y/n) ?: ');
readln(ChkUsr);
MkeDrv := (ChkUsr= 'Y') or (ChkUsr = 'y');
writeln
end;
if MkeDrv then
begin
writeln('Creating ', DrvPth + FLENME);
writeln;
rewrite(F, SECSZE);
fillchar(Sector, SECSZE, $E5);
for i := 1 to HDDSEC do
begin
blockwrite(F, Sector, 1);
if i mod SECTRK = 0 then
write(^M, i:5, ' of ', HDDSEC)
end;
close(F);
writeln;
writeln;
writeln('Z80 hard disk file created')
end;
Setfattr(F, ReadOnly);
end.