1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-06-01 19:41:36 +00:00

Compare commits

...

40 Commits
v2.1 ... master

Author SHA1 Message Date
David Schmenk
3fd11ca0d4 llow single step and quit options during executions of 6502 simulation 2024-03-16 11:26:22 -07:00
David Schmenk
31d5b8a5ec Add some terminal control to Apple1 emulation 2024-03-12 13:57:15 -07:00
dschmenk
82a1632bfd Quick updates 2024-03-09 16:12:05 -08:00
David Schmenk
db424e9fc7 Add single stepping to lib6502 adn complete Apple 1+CFFA emulation 2024-03-09 15:13:07 -08:00
dschmenk
8344f18612 Add lib6502 to make an Apple1+CFFA1 emulator for testing PLASMA 2024-03-08 19:48:10 -08:00
David Schmenk
2b9eb6a5fc Fix A1PLASMA type and aux type and update image 2024-03-07 18:38:35 -08:00
David Schmenk
c23cb6d239 Clean up module loading and images 2024-03-07 18:36:47 -08:00
David Schmenk
1d099df299 Update images 2024-03-07 15:45:17 -08:00
David Schmenk
7aeda2d98b Fix case tatement in self hosted compiler and Apple 1 module loading 2024-03-07 15:18:15 -08:00
David Schmenk
d90b7ba69d Update DHGR Toolkit- 2024-03-01 15:51:08 -08:00
David Schmenk
2eea9e585c DHGR test lib 2024-02-28 13:32:08 -08:00
Dave Schmenk
0ab16d4877 Fix asm example code 2024-02-26 15:25:17 -08:00
David Schmenk
7d669e97b8
Changlist to 2.11 2024-02-26 13:44:54 -08:00
David Schmenk
a1c49d2705 Update SOS images 2024-02-26 13:06:38 -08:00
David Schmenk
578d002b8c Standard REL files load as MODKEEP and update ProDOS images 2024-02-26 12:57:11 -08:00
David Schmenk
7527a5a7d3 Can't forget the assembly include helper files 2024-02-25 13:10:32 -08:00
David Schmenk
b3d1dfed7d
Update Version 2.1.md 2024-02-25 12:08:53 -08:00
David Schmenk
0190c2c3cd
Fix typos and add info 2024-02-25 11:18:41 -08:00
David Schmenk
6f61b4ae8a
Formatting 2024-02-25 10:34:36 -08:00
David Schmenk
e02c068706
Info about assembly language toolkit 2024-02-25 10:32:24 -08:00
David Schmenk
e7ce06fe62
Fix raw links to disk images 2024-02-25 10:18:43 -08:00
David Schmenk
90cfcd2840
Fix HD link 2024-02-25 10:16:07 -08:00
David Schmenk
1e368ced63
Fix link to HD image 2024-02-25 10:14:32 -08:00
David Schmenk
6e45185cfd
Fix links to full images 2024-02-25 10:13:03 -08:00
David Schmenk
db2f9eecc3 Update HD image to 2.11 w/ ASM Toolkit 2024-02-25 10:10:43 -08:00
David Schmenk
5eefe74c6b Update 2.11 2024-02-25 09:59:37 -08:00
David Schmenk
15b14899f4
Add link to assembly toolkit 2024-02-25 09:52:49 -08:00
David Schmenk
d5803ceba9
2.11 Update 2024-02-25 09:50:47 -08:00
David Schmenk
34624f3162
Release 2.11 2024-02-25 09:47:02 -08:00
David Schmenk
b1d463f4e4 Update images to 2.11 2024-02-25 09:16:43 -08:00
David Schmenk
d3b9fe14a0 Add new ASM build tools/files 2024-02-24 11:25:07 -08:00
David Schmenk
6efc2b1a98 Update module loader to handle 8 bit fixups generated by EDASM 2024-02-24 11:13:46 -08:00
David Schmenk
a89b1b9b40 Add EDASM sample code 2024-02-23 17:06:41 -08:00
David Schmenk
9038c7e649
Update Version 2.1.md 2024-02-18 13:37:47 -08:00
David Schmenk
f5c562eafb Clean up dhgrPlot 2024-02-18 09:56:33 -08:00
David Schmenk
2f7c1b3e59 First pass at DHGR toolkit 2024-02-17 18:48:03 -08:00
David Schmenk
631034034c Start DHGR TOOLKIT 2024-02-17 12:12:03 -08:00
David Schmenk
c64843b1e1
Update README.md 2024-02-15 13:46:05 -08:00
David Schmenk
88960e6745
Update README.md 2024-02-15 13:32:51 -08:00
David Schmenk
b4ab21f80c
Update README.md 2024-02-15 13:29:11 -08:00
62 changed files with 3897 additions and 194 deletions

View File

@ -1,21 +1,10 @@
# 2/15/2024 PLASMA 2.1 Available!
# 2/25/2024 PLASMA 2.11 Available!
[Download and read the Release Notes](https://github.com/dschmenk/PLASMA/blob/master/doc/Version%202.1.md)
[Change List](https://github.com/dschmenk/PLASMA/blob/master/doc/Version%202.1.md#changes-in-plasma-for-21-release)
[Change List](https://github.com/dschmenk/PLASMA/blob/master/doc/Version%202.1.md#changes-in-plasma-for-211-release)
[Get single boot floppy for FORTH for PLASMA 2.1](https://github.com/dschmenk/PLASMA/blob/master/doc/PLFORTH.md)
# 3/24/2023 PLASMA 2.0 Available!
Only 5 years in the making!
[Download and read the Release Notes](https://github.com/dschmenk/PLASMA/blob/master/doc/Version%202.0.md)
[Change List](https://github.com/dschmenk/PLASMA/blob/master/doc/Version%202.0.md#changes-in-plasma-for-20-release)
# 4/29/2018 PLASMA 1.2 Available!
[Download and read the Release Notes](https://github.com/dschmenk/PLASMA/blob/master/doc/Version%201.2.md)
[Get single boot floppy of FORTH for PLASMA 2.11](https://github.com/dschmenk/PLASMA/blob/master/images/apple/PLFORTH.PO)
# The PLASMA Programming Language
@ -34,8 +23,6 @@ Different projects have led to the architecture of PLASMA, most notably Apple Pa
<!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 -->
- [3/24/2023 PLASMA 2.0 Available!](#3242023-plasma-20-available)
- [4/29/2018 PLASMA 1.2 Available!](#4292018-plasma-12-available)
- [The PLASMA Programming Language](#the-plasma-programming-language)
- [Contents](#contents)
- [Build Environment](#build-environment)

View File

@ -1,28 +1,38 @@
# PLASMA Version 2.1
# PLASMA Version 2.11
Welcome to PLASMA: the Grand Unifying Platform for the Apple 1, ][, and ///.
Download the five disk images:
Version 2.11 is a minor update to address the relocating loader for EDASM generated modules with 8 bit fixups. All modules up to now have been generated by PLASM and only use 16 bit fixups. Mostly usefull for future modules built with EDASM. Check out the Assembly Language Toolkit below.
[PLASMA 2.1 800K Full System](https://github.com/dschmenk/PLASMA/blob/master/images/apple/PLASMA-2.1.2mg?raw=true)
If you already have 2.1 installed, here are the updated files:
[PLASMA 2.1 ProDOS Boot & Install](https://github.com/dschmenk/PLASMA/blob/master/images/apple/PLASMA-2.1-INST.po?raw=true)
[PLASMA 2.11 Update](https://github.com/dschmenk/PLASMA/raw/master/images/apple/PLASMA-2.11-UPD.po)
[PLASMA 2.1 System Libraries](https://github.com/dschmenk/PLASMA/blob/master/images/apple/PLASMA-2.1-SYS.po?raw=true)
Download the full 2.11 disk image set:
[PLASMA 2.1 Build Tools](https://github.com/dschmenk/PLASMA/blob/master/images/apple/PLASMA-2.1-BLD.po?raw=true)
[PLASMA 2.11 HD Full System](https://github.com/dschmenk/PLASMA/raw/master/images/apple/PLASMA2.2mg)
[PLASMA 2.1 Demos](https://github.com/dschmenk/PLASMA/blob/master/images/apple/PLASMA-2.1-DEMOS.po?raw=true)
[PLASMA 2.11 800K Full System](https://github.com/dschmenk/PLASMA/raw/master/images/apple/PLASMA-2.1.po)
[PLASMA 2.1 TCP/IP network modules](https://github.com/dschmenk/PLASMA/blob/master/images/apple/PLASMA-2.1-INET.po?raw=true)
[PLASMA 2.11 ProDOS Boot & Install](https://github.com/dschmenk/PLASMA/raw/master/images/apple/PLASMA-2.1-INST.po)
[PLASMA 2.1 Apple /// SOS and SANE floating point modules](https://github.com/dschmenk/PLASMA/blob/master/images/apple/PLASMA-2.1-FPSOS.po?raw=true)
[PLASMA 2.1 System Libraries](https://github.com/dschmenk/PLASMA/raw/master/images/apple/PLASMA-2.1-SYS.po)
[PLASMA 2.1 Apple /// SOS Mame Boot](https://github.com/dschmenk/PLASMA/blob/master/images/apple/PLASMA2-A3MAME.PO?raw=true)
[PLASMA 2.11 Build Tools](https://github.com/dschmenk/PLASMA/raw/master/images/apple/PLASMA-2.1-BLD.po)
[PLASMA 2.1 Apple /// Mame hard disk image](https://github.com/dschmenk/PLASMA/blob/master/images/apple/apple3.hd?raw=true)
[PLASMA 2.1 Demos](https://github.com/dschmenk/PLASMA/raw/master/images/apple/PLASMA-2.1-DEMOS.po)
[PLASMA 2.1 PLFORTH stand-alone boot](https://github.com/dschmenk/PLASMA/blob/master/images/apple/PLFORTH.PO?raw=true)
[PLASMA 2.1 TCP/IP network modules](https://github.com/dschmenk/PLASMA/raw/master/images/apple/PLASMA-2.1-INET.po)
[PLASMA 2.11 Apple /// SOS and SANE floating point modules](https://github.com/dschmenk/PLASMA/raw/master/images/apple/PLASMA-2.1-FPSOS.po)
[PLASMA 2.11 Apple /// SOS Mame Boot](https://github.com/dschmenk/PLASMA/raw/master/images/apple/PLASMA2-A3MAME.PO)
[PLASMA 2.11 Apple /// Mame hard disk image](https://github.com/dschmenk/PLASMA/raw/master/images/apple/apple3.hd)
[PLASMA 2.11 PLFORTH stand-alone boot](https://github.com/dschmenk/PLASMA/raw/master/images/apple/PLFORTH.PO)
[PLASMA 2.11 Assembly Language Toolkit](https://github.com/dschmenk/PLASMA/raw/master/images/apple/ASM-TK.po)
PLASMA now has a ProDOS hard disk install script. Mass storage is the recommended installation that looks like (replacing HARDISK with your volume name of choice) if you want to copy files yourself:
@ -102,6 +112,14 @@ The build disk includes sample source, include files for the system modules, and
```
Compiler warnings are enabled with `-W`. The optional optimizer is enabled with `-O` and extra optimizations are enabled with `-O2`. The source code for a few sample programs are included. The big one, `RPNCALC.PLA`, is the sample RPN calculator that uses many of PLASMA's advanced features. The self-hosted compiler is the same compiler as the cross-compiler, just transcribed from C to PLASMA (yes, the self-hosted PLASMA compiler is written in PLASMA). It requires patience when compiling: it is a fairly large and extensive program.
## Assembly Toolkit
New for 2.11 is the assembly language toolkit. The PLASMA module was originally architected around the REL file generated by the ProDOS toolkit assembler, EDASM. This minor update fixes the PLASMA relocating loader to handle 8 bit fixups. PLASM generated modules only use 16 bit fixups, so not an issue for existing modules. Download the toolkit that includes the ProDOS EDASM assembler and sample code. Also the 2.11 updates (if you have 2.1 already installed) here:
[PLASMA 2.11 Assembly Language Toolkit](https://github.com/dschmenk/PLASMA/raw/master/images/apple/ASM-TK.po)
[PLASMA 2.11 Update](https://github.com/dschmenk/PLASMA/raw/master/images/apple/PLASMA-2.11-UPD.po)
## FORTH Module
New for version 2.1 is a FORTH language module capable of interpreting script files and interactive programming. Further documentation here: https://github.com/dschmenk/PLASMA/blob/master/doc/PLFORTH.md. Samples scripts are in /HARDISK/BLD/SCRIPTS
@ -128,6 +146,10 @@ There is a [YouTube playlist](https://www.youtube.com/playlist?list=PLlPKgUMQbJ7
- The documentation is sparse and incomplete. Yep, could use your help...
# Changes in PLASMA for 2.11 Release
1. Minor update to load modules generated by EDASM with 8 bit fixups
# Changes in PLASMA for 2.1 Release
1. Lots of small bug fixes in floating point, file copy and graphics libraries

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

BIN
images/apple/A1PLASMA.po Executable file

Binary file not shown.

BIN
images/apple/ASM-TK.po Executable file

Binary file not shown.

BIN
images/apple/DHGR-TK.po Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,7 +2,7 @@ import cmdsys
//
// Useful values for everyone
//
const _SYSVER_ = $0210 // Version built against
const _SYSVER_ = $0211 // Version built against
const FALSE = 0
const TRUE = not FALSE
const NULL = 0

11
src/inc/extdefseg.inc Normal file
View File

@ -0,0 +1,11 @@
;
; BYTECODE DEFS SEGMENT
;
DB 0 ; PAD BYE
DEFSEG EQU *
;
; INIT CODE RUNS WHEN MODULE LOADED
;
MODINIT DB $54 ; CALL ASM INIT
DW INIT
DB $5C ; RET

5
src/inc/extheader.inc Normal file
View File

@ -0,0 +1,5 @@
DW $6502
DW RESFLAGS ; SYSFLAGS
DW DEFSEG ; DEF OFFSET
DW 1 ; DEF COUNT (INCLUDING INIT)
DW MODINIT ; MOD INIT

41
src/inc/plasma.inc Normal file
View File

@ -0,0 +1,41 @@
REL
ORG $1000
;
; USEFUL ZERO PAGE LOCATIONS
;
SRC EQU $06
SRCL EQU SRC
SRCH EQU SRC+1
DST EQU SRC+2
DSTL EQU DST
DSTH EQU DST+1
TMP EQU $E7
TMPL EQU TMP
TMPH EQU TMP+1
ESTKH EQU $C0
ESTKL EQU $D0
DROPOP EQU $EF
NEXTOP EQU $F0
FETCHOP EQU NEXTOP+1
;
; JUMP TO BYTECODE INTERPRETER ADDRESS
;
INTERP EQU $03D0
;
; SYSTEM FLAGS: MEMORY ALLOCATOR SCREEN HOLES
;
RESTXT1 EQU $0001
RESTXT2 EQU $0002
RESXTXT1 EQU $0004
RESXTXT2 EQU $0008
RESHGR1 EQU $0010
RESHGR2 EQU $0020
RESXHGR1 EQU $0040
RESXHGR2 EQU $0080
NOJITC EQU $0100
;
; MODULE FREE FLAGS
;
MODNOKEEP EQU $0000
MODKEEP EQU $2000
MODINITKEEP EQU $4000

83
src/lib6502/BSDmakefile Normal file
View File

@ -0,0 +1,83 @@
# THIS FILE WAS GENERATED AUTOMATICALLY
# EDIT AT YOUR OWN RISK
#
# Makefile for lib6502, run6502
# Copyright (c) 2005 Ian Piumarta
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sub-license, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS". USE ENTIRELY AT YOUR OWN RISK.
# last edited: 2005-11-01 22:48:49 by piumarta on margaux.local
CFLAGS = -g -O3
PREFIX = /usr/local
BINDIR = $(PREFIX)/bin
LIBDIR = $(PREFIX)/lib
INCDIR = $(PREFIX)/include
DOCDIR = $(PREFIX)/doc/lib6502
EGSDIR = $(DOCDIR)/examples
MANDIR = $(PREFIX)/man
MAN1DIR = $(MANDIR)/man1
MAN3DIR = $(MANDIR)/man3
all : run6502
run6502 : run6502.o lib6502.a
lib6502.a : lib6502.o
$(AR) -rc $@.new lib6502.o
mv $@.new $@
-ranlib $@
clean : .FORCE
rm -f run6502 lib1 *~ *.o *.a .gdb* *.img *.log
.FORCE :
install : .FORCE
install -d $(BINDIR)
install -d $(LIBDIR)
install -d $(INCDIR)
install -d $(MANDIR)
install -d $(MAN1DIR)
install -d $(MAN3DIR)
install -d $(DOCDIR)
install -d $(EGSDIR)
install -c run6502 $(BINDIR)/run6502
install -c lib6502.a $(LIBDIR)/lib6502.a
install -c lib6502.h $(INCDIR)/lib6502.h
install -c man/run6502.1 $(MAN1DIR)/run6502.1
install -c man/lib6502.3 $(MAN3DIR)/lib6502.3
install -c man/M6502_delete.3 $(MAN3DIR)/M6502_delete.3
install -c man/M6502_disassemble.3 $(MAN3DIR)/M6502_disassemble.3
install -c man/M6502_dump.3 $(MAN3DIR)/M6502_dump.3
install -c man/M6502_getCallback.3 $(MAN3DIR)/M6502_getCallback.3
install -c man/M6502_getVector.3 $(MAN3DIR)/M6502_getVector.3
install -c man/M6502_irq.3 $(MAN3DIR)/M6502_irq.3
install -c man/M6502_new.3 $(MAN3DIR)/M6502_new.3
install -c man/M6502_nmi.3 $(MAN3DIR)/M6502_nmi.3
install -c man/M6502_reset.3 $(MAN3DIR)/M6502_reset.3
install -c man/M6502_run.3 $(MAN3DIR)/M6502_run.3
install -c man/M6502_setCallback.3 $(MAN3DIR)/M6502_setCallback.3
install -c man/M6502_setVector.3 $(MAN3DIR)/M6502_setVector.3
install -c ChangeLog $(DOCDIR)/ChangeLog
install -c COPYING $(DOCDIR)/COPYING
install -c README $(DOCDIR)/README
install -c examples/README $(EGSDIR)/README
install -c examples/lib1.c $(EGSDIR)/lib1.c
install -c examples/hex2bin $(EGSDIR)/hex2bin
uninstall : .FORCE
rm -f $(BINDIR)/run6502 $(LIBDIR)/lib6502.a $(INCDIR)/lib6502.h $(MAN1DIR)/run6502.1 $(MAN3DIR)/lib6502.3 $(MAN3DIR)/M6502_delete.3 $(MAN3DIR)/M6502_disassemble.3 $(MAN3DIR)/M6502_dump.3 $(MAN3DIR)/M6502_getCallback.3 $(MAN3DIR)/M6502_getVector.3 $(MAN3DIR)/M6502_irq.3 $(MAN3DIR)/M6502_new.3 $(MAN3DIR)/M6502_nmi.3 $(MAN3DIR)/M6502_reset.3 $(MAN3DIR)/M6502_run.3 $(MAN3DIR)/M6502_setCallback.3 $(MAN3DIR)/M6502_setVector.3 $(DOCDIR)/ChangeLog $(DOCDIR)/COPYING $(DOCDIR)/README $(EGSDIR)/README $(EGSDIR)/lib1.c $(EGSDIR)/hex2bin
rmdir $(EGSDIR) $(DOCDIR)

26
src/lib6502/COPYING Normal file
View File

@ -0,0 +1,26 @@
Distasteful though it is for me to have to induce from afar any perturbation
into your pursuit of happiness, this MIT (X11 flavour) license is at least
relatively benign. Investigation into copyright stupidity reveals that it is
effectively impossible to dedicate (formally) any software to the public
domain (the only sure path to this most enlightened status being to leave the
software to expire naturally from its 25-, 50-, 75- or whatever-year copyright
rot). I fear this is not going to change before the revolution comes. In the
meantime the only way I can *guarantee* you any rights at all to this software
would (unfortunately) appear to be...
Copyright (c) 2005 Ian Piumarta
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to
do so, provided that the above copyright notice(s) and this permission
notice appear in all copies or substantial portions of the Software.
Inclusion of the above copyright notice(s) and this permission notice in
supporting documentation would be appreciated, but is not required.
THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK.

7
src/lib6502/ChangeLog Normal file
View File

@ -0,0 +1,7 @@
2005-11-01 Ian Piumarta <com -dot- gmail -at- piumarta (backwards)>
* RELEASE 1.0
2005-10-30 Ian Piumarta <com -dot- gmail -at- piumarta (backwards)>
* ChangeLog: created.

232
src/lib6502/Makefile Normal file
View File

@ -0,0 +1,232 @@
# Makefile for lib6502, run6502
# Copyright (c) 2005 Ian Piumarta
#
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the 'Software'), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, provided
# that the above copyright notice(s) and this permission notice appear
# in all copies of the Software and that both the above copyright
# notice(s) and this permission notice appear in supporting
# documentation.
#
# THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK.
# last edited: 2013-06-08 01:08:02 by piumarta on vps2.piumarta.com
CFLAGS = -g -O3
PREFIX = /usr/local
BINDIR = $(PREFIX)/bin
LIBDIR = $(PREFIX)/lib
INCDIR = $(PREFIX)/include
DOCDIR = $(PREFIX)/doc/lib6502
EGSDIR = $(DOCDIR)/examples
MANDIR = $(PREFIX)/man
MAN1DIR = $(MANDIR)/man1
MAN3DIR = $(MANDIR)/man3
all : run6502
run6502 : run6502.o lib6502.a
lib6502.a : lib6502.o
$(AR) -rc $@.new lib6502.o
mv $@.new $@
-ranlib $@
clean : .FORCE
rm -f run6502 lib1 *~ *.o *.a .gdb* *.img *.log
.FORCE :
# ----------------------------------------------------------------
INSTALLDIRS = $(BINDIR) $(LIBDIR) $(INCDIR) $(MANDIR) $(MAN1DIR) $(MAN3DIR) $(DOCDIR) $(EGSDIR)
BINFILES = $(BINDIR)/run6502
LIBFILES = $(LIBDIR)/lib6502.a
INCFILES = $(INCDIR)/lib6502.h
MANFILES = $(MAN1DIR)/run6502.1 \
$(MAN3DIR)/lib6502.3 \
$(MAN3DIR)/M6502_delete.3 \
$(MAN3DIR)/M6502_disassemble.3 \
$(MAN3DIR)/M6502_dump.3 \
$(MAN3DIR)/M6502_getCallback.3 \
$(MAN3DIR)/M6502_getVector.3 \
$(MAN3DIR)/M6502_irq.3 \
$(MAN3DIR)/M6502_new.3 \
$(MAN3DIR)/M6502_nmi.3 \
$(MAN3DIR)/M6502_reset.3 \
$(MAN3DIR)/M6502_run.3 \
$(MAN3DIR)/M6502_setCallback.3 \
$(MAN3DIR)/M6502_setVector.3
DOCFILES = $(DOCDIR)/ChangeLog \
$(DOCDIR)/COPYING \
$(DOCDIR)/README \
$(EGSDIR)/README \
$(EGSDIR)/lib1.c \
$(EGSDIR)/hex2bin
MKDIR = install -d
RMDIR = rmdir
INSTALL = install -c
RM = rm -f
$(BINDIR)/% $(LIBDIR)/% $(INCDIR)/% $(DOCDIR)/% : %
$(INSTALL) $< $@
$(MAN1DIR)/% $(MAN3DIR)/% : man/%
$(INSTALL) $< $@
$(EGSDIR)/% : examples/%
$(INSTALL) $< $@
$(INSTALLDIRS) :
$(MKDIR) $@
install : $(INSTALLDIRS) $(BINFILES) $(LIBFILES) $(INCFILES) $(MANFILES) $(DOCFILES)
uninstall : .FORCE
-$(RM) $(BINFILES) $(LIBFILES) $(INCFILES) $(MANFILES) $(DOCFILES)
-$(RMDIR) $(EGSDIR) $(DOCDIR)
# ----------------------------------------------------------------
PACKAGE_VERSION = 1.3
PACKAGE_TARNAME = lib6502
TARNAME= $(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
DISTFILES = \
$(TARNAME)/ChangeLog \
$(TARNAME)/COPYING \
$(TARNAME)/README \
$(TARNAME)/Makefile \
$(TARNAME)/BSDmakefile \
$(TARNAME)/config.h \
$(TARNAME)/lib6502.h \
$(TARNAME)/lib6502.c \
$(TARNAME)/run6502.c \
$(TARNAME)/test.out \
$(TARNAME)/man/run6502.1 \
$(TARNAME)/man/lib6502.3 \
$(TARNAME)/man/M6502_delete.3 \
$(TARNAME)/man/M6502_disassemble.3 \
$(TARNAME)/man/M6502_dump.3 \
$(TARNAME)/man/M6502_getCallback.3 \
$(TARNAME)/man/M6502_getVector.3 \
$(TARNAME)/man/M6502_irq.3 \
$(TARNAME)/man/M6502_new.3 \
$(TARNAME)/man/M6502_nmi.3 \
$(TARNAME)/man/M6502_reset.3 \
$(TARNAME)/man/M6502_run.3 \
$(TARNAME)/man/M6502_setCallback.3 \
$(TARNAME)/man/M6502_setVector.3 \
$(TARNAME)/examples/hex2bin \
$(TARNAME)/examples/lib1.c \
$(TARNAME)/examples/README
dist : .FORCE
rm -f $(TARNAME)
ln -s . $(TARNAME)
tar -cf $(TARNAME).tar $(DISTFILES)
gzip -v9 $(TARNAME).tar
rm -f $(TARNAME)
dist-test : .FORCE
rm -rf $(TARNAME)
tar -xz -f $(TARNAME).tar.gz
ln -s ../images $(TARNAME)/images
$(MAKE) -C $(TARNAME) test
rm -rf $(TARNAME)
# ----------------------------------------------------------------
image :
./run6502 \
-l C000 images/os1.2 \
-l 8000 images/basic2 \
-s 0000 +10000 image \
-x
newimage : .FORCE
rm -f image
$(MAKE) image
test1 : run6502 .FORCE
echo a2418a20eeffe8e05bd0f7a90a20eeff0000 | perl -e '$$_=pack"H*",<STDIN>;print' > temp.img
./run6502 \
-l 1000 temp.img \
-d 1000 +11 \
-R 1000 \
-P FFEE \
-X 0
lib1 : lib6502.a
$(CC) -I. -o lib1 examples/lib1.c lib6502.a
test2 : lib1 .FORCE
./lib1
test3 : run6502 image .FORCE
echo 'PRINT:FORA%=1TO10:PRINTA%:NEXT:PRINT"HELLO WORLD"' | ./run6502 image
test4 : run6502 image .FORCE
echo 'P%=&2800:O%=P%:[opt3:ldx#65:.l txa:jsr&FFEE:inx:cpx#91:bnel:lda#13:jsr&FFEE:lda#10:jmp&FFEE:]:CALL&2800' | ./run6502 image
test : run6502 lib1 image .FORCE
@$(MAKE) test1 test2 test3 test4 | grep -v '^make.* directory' | tee test.log
cmp test.log test.out
@echo
@echo SUCCESS
@echo
# ----------------------------------------------------------------
# I don't know what it is (probably me, who knows?) but every single
# time I try to write a Makefile that is compatible with both GNU and
# BSD make I spend three hours getting absolutely nowhere. It's
# telling when a program consisting of precisely TWO SOURCE FILES and
# a few man pages and examples is already TOO COMPLEX to be installed
# with BSD make, in the absence of an explicit rule for every single
# target, be it installed or intermediate, from a Makefile that won't
# also break GNU make. Good Grief Charlie Brown.
# Yes I know I can compose the sed substitutions into a single script,
# but it looks even uglier that way.
BSDmakefile : .FORCE
$(MAKE)
rm -rf /tmp/bsd
echo '# THIS FILE WAS GENERATED AUTOMATICALLY' > BSDmakefile
echo '# EDIT AT YOUR OWN RISK' >> BSDmakefile
echo '# ' >> BSDmakefile
sed '/# -/,$$d' < Makefile >> BSDmakefile
echo 'install : .FORCE' > BSDtemp
$(MAKE) install PREFIX=/tmp/bsd >> BSDtemp
echo >> BSDtemp
echo 'uninstall : .FORCE' >> BSDtemp
$(MAKE) uninstall PREFIX=/tmp/bsd >> BSDtemp
cat BSDtemp | \
sed 's,/tmp/bsd/doc/lib6502/examples,$$(EGSDIR),g' | \
sed 's,/tmp/bsd/doc/lib6502,$$(DOCDIR),g' | \
sed 's,/tmp/bsd/man/man1,$$(MAN1DIR),g' | \
sed 's,/tmp/bsd/man/man3,$$(MAN3DIR),g' | \
sed 's,/tmp/bsd/man,$$(MANDIR),g' | \
sed 's,/tmp/bsd/include,$$(INCDIR),g' | \
sed 's,/tmp/bsd/lib,$$(LIBDIR),g' | \
sed 's,/tmp/bsd/lib,$$(LIBDIR),g' | \
sed 's,/tmp/bsd/bin,$$(BINDIR),g' | \
sed 's,^, ,g' >> BSDmakefile
rm -f BSDtemp
rm -rf /tmp/bsd

131
src/lib6502/README Executable file
View File

@ -0,0 +1,131 @@
lib6502 - 6502 Microprocessor Emulator
Version: 1.0
WHAT IF I'M TOO LAZY TO READ 'README'S?
make
make install
more examples/README
WHAT IS LIB6502?
lib6502 is a library that emulates the 6502 microprocessor. It
comes with a small 'shell', run6502, that can execute 6502 programs
from the command line.
lib6502 is distributed under the MIT license: it is non-infectious
and will not make your projects contagious to others the instant you
choose to use lib6502 in them. See the file COPYING for details.
WHERE IS THE LATEST SOURCE CODE?
Source code for lib6502 is available from the author's home page at
'http://piumarta.com/software'. You can download the most recent
release or use Subversion to get the very latest sources.
WHERE IS THE DOCUMENTATION?
Manual pages for run6502 and lib6502 (and all the functions it
exports) should be available once it is installed. Each includes a
short 'examples' section. Use the 'man' command to read them.
Your best place to start looking for documentation on the 6502
itself is 'http://6502.org'. A google search of the web will also
turn up vast quantities of information about (and programs for) the
6502.
HOW DO I INSTALL IT?
It's not really big enough to warrant the whole 'configure' thing.
Any system with an ANSI compiler and C library should be able to
compile it out of the box. After unpacking the archive, just type:
make
to build it. If the compiler blows up immediately, edit the
Makefile and play with the '-g' and '-O' flags and then try again.
If you really can't make the compiler happy you've found a bug (read
the next section but one). Otherwise, if you want it put it
somewhere more permanent then type:
make install
(as root) to install it. It goes into /usr/local by default; if you
want it elsewhere then set PREFIX in the make command. For example:
make install PREFIX=/usr
will put everything under '/usr'.
When you get bored with it, go back to the source directory and
type:
make uninstall
(with the same PREFIX you specified during the install, if
necessary.)
WHAT CAN I DO WITH IT?
See the file EXAMPLES for some suggestions (all of them polite).
If that leaves you wanting more, read the source for run6502 -- it
exercises just about every feature in lib6502.
HOW DO I REPORT PROBLEMS?
Send e-mail to the author at: firstName (at) lastName (dot) com
(For suitable values of firstName and lastName, see the last section
of this file.)
If you're still confused, contact him at: http://piumarta.com
HOW CAN I HELP?
Use it. Find bugs. Fix bugs. Make it faster. Evangelism: spread
it to as many other projects as possible, especially those that
might be using a slower emulator! Read the manual pages to see
what's considered missing, then add it, then send it in.
(One thing that would be be really handy, and isn't mentioned in the
manual pages, is a test suite. Figure out how to test every mode in
every instruction with every possible combination of operand values
and condition codes and verify the behaviour is correct. Then write
it down in the form of a program and send it in. If it's a
self-contained program that runs once to completion then we can
probably find some real hardware to test against the test suite.)
If you know how to write software that emulates peripheral hardware
devices, google up some details on the popular 6502-based
microcomputers (Acorn, Commodore, etc.) and add some serious system
emulation to run6502. Make it all pluggable (think dynamic
libraries over an 'agnostic' core), so we can change machines at the
flip of a (command-line) switch. (The callback mechanism in lib6502
was designed with this kind of 'pluggable hardware emulation' in
mind.)
WHO WROTE THIS STUFF, AND WHY?
lib6502 was written by Ian Piumarta.
While writing ccg (an entirely different project that creates
runtime assemblers for dynamic code generators) he decided to
include support for an 8-bit microprocessor, just for fun. He chose
the 6502 because it was used in the first computer he owned and
programmed (an Ohio Scientific Superboard II, when he was 14) as
well as the second (an Acorn 'BBC Model B', about four years later).
lib6502 started as a 'glorified switch statement' that ran some
small test programs spewed into memory by ccg, but rapidly got out
of control over the course of a weekend. You're looking at the
result.

267
src/lib6502/a1cffa.c Normal file
View File

@ -0,0 +1,267 @@
/* run6502.c -- 6502 emulator shell -*- C -*- */
/* Copyright (c) 2005 Ian Piumarta
*
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the 'Software'),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, provided that the above copyright notice(s) and this
* permission notice appear in all copies of the Software and that both the
* above copyright notice(s) and this permission notice appear in supporting
* documentation.
*
* THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK.
*/
/* Last edited: 2005-11-02 01:18:58 by piumarta on margaux.local
*/
/* Apple 1 + CFFA1 support for PLASMA by resman
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <termios.h>
#include "config.h"
#include "lib6502.h"
#define VERSION PACKAGE_NAME " " PACKAGE_VERSION " " PACKAGE_COPYRIGHT
typedef uint8_t byte;
typedef uint16_t word;
struct termios org_tio;
void pfail(const char *msg)
{
fflush(stdout);
perror(msg);
exit(1);
}
#define rts \
{ \
word pc; \
pc = mpu->memory[++mpu->registers->s + 0x100]; \
pc |= mpu->memory[++mpu->registers->s + 0x100] << 8; \
return pc + 1; \
}
int save(M6502 *mpu, word address, unsigned length, const char *path)
{
FILE *file;
int count;
if (!(file = fopen(path, "wb")))
return 0;
while ((count = fwrite(mpu->memory + address, 1, length, file)))
{
address += count;
length -= count;
}
fclose(file);
return 1;
}
int load(M6502 *mpu, word address, const char *path)
{
FILE *file;
int count;
size_t max = 0x10000 - address;
if (!(file = fopen(path, "rb")))
return 0;
while ((count = fread(mpu->memory + address, 1, max, file)) > 0)
{
address += count;
max -= count;
}
fclose(file);
return 1;
}
//
// CFFA1 zero page addresses.
//
#define CFFADest 0x00
#define CFFAFileName 0x02
#define CFFAOldName 0x04
#define CFFAFileType 0x06
#define CFFAAuxType 0x07
#define CFFAFileSize 0x09
#define CFFAEntryPtr 0x0B
int cffa1(M6502 *mpu, word address, byte data)
{
char *fileptr, filename[64];
int addr;
struct stat sbuf;
switch (mpu->registers->x)
{
case 0x02: /* quit */
exit(0);
break;
case 0x14: /* find dir entry */
addr = mpu->memory[CFFAFileName] | (mpu->memory[CFFAFileName + 1] << 8);
memset(filename, 0, 64);
strncpy(filename, (char *)(mpu->memory + addr + 1), mpu->memory[addr]);
strcat(filename, "#FE1000");
if (!(stat(filename, &sbuf)))
{
/* DirEntry @ $9100 */
mpu->memory[CFFAEntryPtr] = 0x00;
mpu->memory[CFFAEntryPtr + 1] = 0x91;
mpu->memory[0x9115] = sbuf.st_size;
mpu->memory[0x9116] = sbuf.st_size >> 8;
mpu->registers->a = 0;
}
else
mpu->registers->a = -1;
break;
case 0x22: /* load file */
addr = mpu->memory[CFFAFileName] | (mpu->memory[CFFAFileName + 1] << 8);
memset(filename, 0, 64);
strncpy(filename, (char *)(mpu->memory + addr + 1), mpu->memory[addr]);
strcat(filename, "#FE1000");
addr = mpu->memory[CFFADest] | (mpu->memory[CFFADest + 1] << 8);
mpu->registers->a = load(mpu, addr, filename) - 1;
break;
default:
{
char state[64];
fprintf(stderr, "Unimplemented CFFA function: %02X\n", mpu->registers->x);
M6502_dump(mpu, state);
fflush(stdout);
fprintf(stderr, "\nCFFA1 %s\n", state);
pfail("ABORT");
}
break;
}
rts;
}
int bye(M6502 *mpu, word addr, byte data) { exit(0); return 0; }
int cout(M6502 *mpu, word addr, byte data) { if (mpu->registers->a == 0x8D) putchar('\n'); putchar(mpu->registers->a & 0x7F); fflush(stdout); rts; }
int paused = 0;
unsigned char keypending = 0;
unsigned char keypressed(M6502 *mpu)
{
unsigned char cin, cext[2];
if (read(STDIN_FILENO, &cin, 1) > 0)
{
if (cin == 0x03) // CTRL-C
{
mpu->flags |= M6502_SingleStep;
paused = 1;
}
if (cin == 0x1B) // Look for left arrow
{
if (read(STDIN_FILENO, cext, 2) == 2 && cext[0] == '[' && cext[1] == 'D')
cin = 0x08;
}
keypending = cin | 0x80;
}
return keypending & 0x80;
}
unsigned char keyin(M6502 *mpu)
{
unsigned char cin;
if (!keypending)
keypressed(mpu);
cin = keypending;
keypending = 0;
return cin;
}
int rd6820kbdctl(M6502 *mpu, word addr, byte data) { return keypressed(mpu); }
int rd6820vidctl(M6502 *mpu, word addr, byte data) { return 0x00; }
int rd6820kbd(M6502 *mpu, word addr, byte data) { return keyin(mpu); }
int rd6820vid(M6502 *mpu, word addr, byte data) { return 0x80; }
int wr6820vid(M6502 *mpu, word addr, byte data) { if (data == 0x8D) putchar('\n'); putchar(data & 0x7F); fflush(stdout); return 0; }
int setTraps(M6502 *mpu)
{
/* Apple 1 memory-mapped IO */
M6502_setCallback(mpu, read, 0xD010, rd6820kbd);
M6502_setCallback(mpu, read, 0xD011, rd6820kbdctl);
M6502_setCallback(mpu, read, 0xD012, rd6820vid);
M6502_setCallback(mpu, write, 0xD012, wr6820vid);
M6502_setCallback(mpu, read, 0xD013, rd6820vidctl);
/* CFFA1 and ROM calls */
M6502_setCallback(mpu, call, 0x9000, bye);
M6502_setCallback(mpu, call, 0x900C, cffa1);
M6502_setCallback(mpu, call, 0xFFEF, cout);
return 0;
}
void resetInput(void)
{
tcsetattr(STDIN_FILENO, TCSANOW, &org_tio);
}
void setRawInput(void)
{
struct termios termio;
// Save input settings.
tcgetattr(STDIN_FILENO, &termio); /* save current port settings */
memcpy(&org_tio, &termio, sizeof(struct termios));
termio.c_cflag = /*BAUDRATE | CRTSCTS |*/ CS8 | CLOCAL | CREAD;
termio.c_iflag = IGNPAR;
termio.c_oflag = 0;
termio.c_lflag = 0; /* set input mode (non-canonical, no echo,...) */
termio.c_cc[VTIME] = 0; /* inter-character timer unused */
termio.c_cc[VMIN] = 0; /* non-blocking read */
tcsetattr(STDIN_FILENO, TCSANOW, &termio);
atexit(resetInput);
}
int main(int argc, char **argv)
{
char *interpfile = "A1PLASMA#060280";
char *program= argv[0];
M6502 *mpu = M6502_new(0, 0, 0);
while (++argv, --argc > 0)
{
if (!strcmp(*argv, "-t")) mpu->flags |= M6502_SingleStep;
else
if (argv[0][0] != '-') interpfile = *argv;
else fprintf(stderr, "Usage: %s [-t] [interpreter file]", program);
}
if (!load(mpu, 0x280, interpfile))
pfail(interpfile);
setRawInput();
setTraps(mpu);
M6502_reset(mpu);
mpu->registers->pc = 0x0280;
while (M6502_run(mpu))
{
char state[64];
char insn[64];
M6502_dump(mpu, state);
M6502_disassemble(mpu, mpu->registers->pc, insn);
printf("%s : %s\r\n", state, insn);
if (paused || (keypressed(mpu) && keypending == 0x83))
{
keypending = 0;
while (!keypressed(mpu));
if (keypending == (0x80|'C'))
paused = 0;
else if (keypending == (0x80|'Q'))
break;
keypending = 0;
}
}
M6502_delete(mpu);
return 0;
}

9
src/lib6502/config.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef __config_h
#define __config_h
#define PACKAGE_NAME "lib6502"
#define PACKAGE_VERSION "1.0"
#define PACKAGE_BUGREPORT "firstName (at) lastName (dot) com"
#define PACKAGE_COPYRIGHT "Copyright (c) 2005 Ian Piumarta"
#endif /* __config_h */

896
src/lib6502/lib6502.c Normal file
View File

@ -0,0 +1,896 @@
/* lib6502.c -- MOS Technology 6502 emulator -*- C -*- */
/* Copyright (c) 2005 Ian Piumarta
*
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the 'Software'),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, provided that the above copyright notice(s) and this
* permission notice appear in all copies of the Software and that both the
* above copyright notice(s) and this permission notice appear in supporting
* documentation.
*
* THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK.
*/
/* Last edited: 2013-06-07 23:03:39 by piumarta on emilia.local
*
* BUGS:
* - RTS and RTI do not check the return address for a callback
* - the disassembler cannot be configured to read two bytes for BRK
* - architectural variations (unimplemented/extended instructions) not implemented
* - ANSI versions (from from gcc extensions) of the dispatch macros are missing
* - emulator+disassembler in same object file (library is kind of pointless)
*/
#include <stdio.h>
#include <stdlib.h>
#include "lib6502.h"
typedef uint8_t byte;
typedef uint16_t word;
enum {
flagN= (1<<7), /* negative */
flagV= (1<<6), /* overflow */
flagX= (1<<5), /* unused */
flagB= (1<<4), /* irq from brk */
flagD= (1<<3), /* decimal mode */
flagI= (1<<2), /* irq disable */
flagZ= (1<<1), /* zero */
flagC= (1<<0) /* carry */
};
#define getN() (P & flagN)
#define getV() (P & flagV)
#define getB() (P & flagB)
#define getD() (P & flagD)
#define getI() (P & flagI)
#define getZ() (P & flagZ)
#define getC() (P & flagC)
#define setNVZC(N,V,Z,C) (P= (P & ~(flagN | flagV | flagZ | flagC)) | (N) | ((V)<<6) | ((Z)<<1) | (C))
#define setNZC(N,Z,C) (P= (P & ~(flagN | flagZ | flagC)) | (N) | ((Z)<<1) | (C))
#define setNZ(N,Z) (P= (P & ~(flagN | flagZ )) | (N) | ((Z)<<1) )
#define setZ(Z) (P= (P & ~( flagZ )) | ((Z)<<1) )
#define setC(C) (P= (P & ~( flagC)) | (C))
#define NAND(P, Q) (!((P) & (Q)))
#define tick(n)
#define tickIf(p)
/* memory access (indirect if callback installed) -- ARGUMENTS ARE EVALUATED MORE THAN ONCE! */
#define putMemory(ADDR, BYTE) \
( writeCallback[ADDR] \
? writeCallback[ADDR](mpu, ADDR, BYTE) \
: (memory[ADDR]= BYTE) )
#define getMemory(ADDR) \
( readCallback[ADDR] \
? readCallback[ADDR](mpu, ADDR, 0) \
: memory[ADDR] )
/* stack access (always direct) */
#define push(BYTE) (memory[0x0100 + S--]= (BYTE))
#define pop() (memory[++S + 0x0100])
/* adressing modes (memory access direct) */
#define implied(ticks) \
tick(ticks);
#define immediate(ticks) \
tick(ticks); \
ea= PC++;
#define abs(ticks) \
tick(ticks); \
ea= memory[PC] + (memory[PC + 1] << 8); \
PC += 2;
#define relative(ticks) \
tick(ticks); \
ea= memory[PC++]; \
if (ea & 0x80) ea -= 0x100; \
tickIf((ea >> 8) != (PC >> 8));
#define indirect(ticks) \
tick(ticks); \
{ \
word tmp; \
tmp= memory[PC] + (memory[PC + 1] << 8); \
ea = memory[tmp] + (memory[tmp + 1] << 8); \
PC += 2; \
}
#define absx(ticks) \
tick(ticks); \
ea= memory[PC] + (memory[PC + 1] << 8); \
PC += 2; \
tickIf((ticks == 4) && ((ea >> 8) != ((ea + X) >> 8))); \
ea += X;
#define absy(ticks) \
tick(ticks); \
ea= memory[PC] + (memory[PC + 1] << 8); \
PC += 2; \
tickIf((ticks == 4) && ((ea >> 8) != ((ea + Y) >> 8))); \
ea += Y
#define zp(ticks) \
tick(ticks); \
ea= memory[PC++];
#define zpx(ticks) \
tick(ticks); \
ea= memory[PC++] + X; \
ea &= 0x00ff;
#define zpy(ticks) \
tick(ticks); \
ea= memory[PC++] + Y; \
ea &= 0x00ff;
#define indx(ticks) \
tick(ticks); \
{ \
byte tmp= memory[PC++] + X; \
ea= memory[tmp] + (memory[tmp + 1] << 8); \
}
#define indy(ticks) \
tick(ticks); \
{ \
byte tmp= memory[PC++]; \
ea= memory[tmp] + (memory[tmp + 1] << 8); \
tickIf((ticks == 5) && ((ea >> 8) != ((ea + Y) >> 8))); \
ea += Y; \
}
#define indabsx(ticks) \
tick(ticks); \
{ \
word tmp; \
tmp= memory[PC ] + (memory[PC + 1] << 8) + X; \
ea = memory[tmp] + (memory[tmp + 1] << 8); \
}
#define indzp(ticks) \
tick(ticks); \
{ \
byte tmp; \
tmp= memory[PC++]; \
ea = memory[tmp] + (memory[tmp + 1] << 8); \
}
/* insns */
#define adc(ticks, adrmode) \
adrmode(ticks); \
{ \
byte B= getMemory(ea); \
if (!getD()) \
{ \
int c= A + B + getC(); \
int v= (int8_t)A + (int8_t)B + getC(); \
fetch(); \
A= c; \
setNVZC((A & 0x80), (((A & 0x80) > 0) ^ (v < 0)), (A == 0), ((c & 0x100) > 0)); \
next(); \
} \
else \
{ \
int l, h, s; \
/* inelegant & slow, but consistent with the hw for illegal digits */ \
l= (A & 0x0F) + (B & 0x0F) + getC(); \
h= (A & 0xF0) + (B & 0xF0); \
if (l >= 0x0A) { l -= 0x0A; h += 0x10; } \
if (h >= 0xA0) { h -= 0xA0; } \
fetch(); \
s= h | (l & 0x0F); \
/* only C is valid on NMOS 6502 */ \
setNVZC(s & 0x80, !(((A ^ B) & 0x80) && ((A ^ s) & 0x80)), !s, !!(h & 0x80)); \
A= s; \
tick(1); \
next(); \
} \
}
#define sbc(ticks, adrmode) \
adrmode(ticks); \
{ \
byte B= getMemory(ea); \
if (!getD()) \
{ \
int b= 1 - (P &0x01); \
int c= A - B - b; \
int v= (int8_t)A - (int8_t) B - b; \
fetch(); \
A= c; \
setNVZC(A & 0x80, ((A & 0x80) > 0) ^ ((v & 0x100) != 0), A == 0, c >= 0); \
next(); \
} \
else \
{ \
/* this is verbatim ADC, with a 10's complemented operand */ \
int l, h, s; \
B= 0x99 - B; \
l= (A & 0x0F) + (B & 0x0F) + getC(); \
h= (A & 0xF0) + (B & 0xF0); \
if (l >= 0x0A) { l -= 0x0A; h += 0x10; } \
if (h >= 0xA0) { h -= 0xA0; } \
fetch(); \
s= h | (l & 0x0F); \
/* only C is valid on NMOS 6502 */ \
setNVZC(s & 0x80, !(((A ^ B) & 0x80) && ((A ^ s) & 0x80)), !s, !!(h & 0x80)); \
A= s; \
tick(1); \
next(); \
} \
}
#define cmpR(ticks, adrmode, R) \
adrmode(ticks); \
fetch(); \
{ \
byte B= getMemory(ea); \
byte d= R - B; \
setNZC(d & 0x80, !d, R >= B); \
} \
next();
#define cmp(ticks, adrmode) cmpR(ticks, adrmode, A)
#define cpx(ticks, adrmode) cmpR(ticks, adrmode, X)
#define cpy(ticks, adrmode) cmpR(ticks, adrmode, Y)
#define dec(ticks, adrmode) \
adrmode(ticks); \
fetch(); \
{ \
byte B= getMemory(ea); \
--B; \
putMemory(ea, B); \
setNZ(B & 0x80, !B); \
} \
next();
#define decR(ticks, adrmode, R) \
fetch(); \
tick(ticks); \
--R; \
setNZ(R & 0x80, !R); \
next();
#define dea(ticks, adrmode) decR(ticks, adrmode, A)
#define dex(ticks, adrmode) decR(ticks, adrmode, X)
#define dey(ticks, adrmode) decR(ticks, adrmode, Y)
#define inc(ticks, adrmode) \
adrmode(ticks); \
fetch(); \
{ \
byte B= getMemory(ea); \
++B; \
putMemory(ea, B); \
setNZ(B & 0x80, !B); \
} \
next();
#define incR(ticks, adrmode, R) \
fetch(); \
tick(ticks); \
++R; \
setNZ(R & 0x80, !R); \
next();
#define ina(ticks, adrmode) incR(ticks, adrmode, A)
#define inx(ticks, adrmode) incR(ticks, adrmode, X)
#define iny(ticks, adrmode) incR(ticks, adrmode, Y)
#define bit(ticks, adrmode) \
adrmode(ticks); \
fetch(); \
{ \
byte B= getMemory(ea); \
P= (P & ~(flagN | flagV | flagZ)) \
| (B & (0xC0)) | (((A & B) == 0) << 1); \
} \
next();
#define tsb(ticks, adrmode) \
adrmode(ticks); \
fetch(); \
{ \
byte b= getMemory(ea); \
b |= A; \
putMemory(ea, b); \
setZ(!b); \
} \
next();
#define trb(ticks, adrmode) \
adrmode(ticks); \
fetch(); \
{ \
byte b= getMemory(ea); \
b |= (A ^ 0xFF); \
putMemory(ea, b); \
setZ(!b); \
} \
next();
#define bitwise(ticks, adrmode, op) \
adrmode(ticks); \
fetch(); \
A op##= getMemory(ea); \
setNZ(A & 0x80, !A); \
next();
#define and(ticks, adrmode) bitwise(ticks, adrmode, &)
#define eor(ticks, adrmode) bitwise(ticks, adrmode, ^)
#define ora(ticks, adrmode) bitwise(ticks, adrmode, |)
#define asl(ticks, adrmode) \
adrmode(ticks); \
{ \
unsigned int i= getMemory(ea) << 1; \
putMemory(ea, i); \
fetch(); \
setNZC(i & 0x80, !i, i >> 8); \
} \
next();
#define asla(ticks, adrmode) \
tick(ticks); \
fetch(); \
{ \
int c= A >> 7; \
A <<= 1; \
setNZC(A & 0x80, !A, c); \
} \
next();
#define lsr(ticks, adrmode) \
adrmode(ticks); \
{ \
byte b= getMemory(ea); \
int c= b & 1; \
fetch(); \
b >>= 1; \
putMemory(ea, b); \
setNZC(0, !b, c); \
} \
next();
#define lsra(ticks, adrmode) \
tick(ticks); \
fetch(); \
{ \
int c= A & 1; \
A >>= 1; \
setNZC(0, !A, c); \
} \
next();
#define rol(ticks, adrmode) \
adrmode(ticks); \
{ \
word b= (getMemory(ea) << 1) | getC(); \
fetch(); \
putMemory(ea, b); \
setNZC(b & 0x80, !(b & 0xFF), b >> 8); \
} \
next();
#define rola(ticks, adrmode) \
tick(ticks); \
fetch(); \
{ \
word b= (A << 1) | getC(); \
A= b; \
setNZC(A & 0x80, !A, b >> 8); \
} \
next();
#define ror(ticks, adrmode) \
adrmode(ticks); \
{ \
int c= getC(); \
byte m= getMemory(ea); \
byte b= (c << 7) | (m >> 1); \
fetch(); \
putMemory(ea, b); \
setNZC(b & 0x80, !b, m & 1); \
} \
next();
#define rora(ticks, adrmode) \
adrmode(ticks); \
{ \
int ci= getC(); \
int co= A & 1; \
fetch(); \
A= (ci << 7) | (A >> 1); \
setNZC(A & 0x80, !A, co); \
} \
next();
#define tRS(ticks, adrmode, R, S) \
fetch(); \
tick(ticks); \
S= R; \
setNZ(S & 0x80, !S); \
next();
#define tax(ticks, adrmode) tRS(ticks, adrmode, A, X)
#define txa(ticks, adrmode) tRS(ticks, adrmode, X, A)
#define tay(ticks, adrmode) tRS(ticks, adrmode, A, Y)
#define tya(ticks, adrmode) tRS(ticks, adrmode, Y, A)
#define tsx(ticks, adrmode) tRS(ticks, adrmode, S, X)
#define txs(ticks, adrmode) \
fetch(); \
tick(ticks); \
S= X; \
next();
#define ldR(ticks, adrmode, R) \
adrmode(ticks); \
fetch(); \
R= getMemory(ea); \
setNZ(R & 0x80, !R); \
next();
#define lda(ticks, adrmode) ldR(ticks, adrmode, A)
#define ldx(ticks, adrmode) ldR(ticks, adrmode, X)
#define ldy(ticks, adrmode) ldR(ticks, adrmode, Y)
#define stR(ticks, adrmode, R) \
adrmode(ticks); \
fetch(); \
putMemory(ea, R); \
next();
#define sta(ticks, adrmode) stR(ticks, adrmode, A)
#define stx(ticks, adrmode) stR(ticks, adrmode, X)
#define sty(ticks, adrmode) stR(ticks, adrmode, Y)
#define stz(ticks, adrmode) stR(ticks, adrmode, 0)
#define branch(ticks, adrmode, cond) \
if (cond) \
{ \
adrmode(ticks); \
PC += ea; \
tick(1); \
} \
else \
{ \
tick(ticks); \
PC++; \
} \
fetch(); \
next();
#define bcc(ticks, adrmode) branch(ticks, adrmode, !getC())
#define bcs(ticks, adrmode) branch(ticks, adrmode, getC())
#define bne(ticks, adrmode) branch(ticks, adrmode, !getZ())
#define beq(ticks, adrmode) branch(ticks, adrmode, getZ())
#define bpl(ticks, adrmode) branch(ticks, adrmode, !getN())
#define bmi(ticks, adrmode) branch(ticks, adrmode, getN())
#define bvc(ticks, adrmode) branch(ticks, adrmode, !getV())
#define bvs(ticks, adrmode) branch(ticks, adrmode, getV())
#define bra(ticks, adrmode) \
adrmode(ticks); \
PC += ea; \
fetch(); \
tick(1); \
next();
#define jmp(ticks, adrmode) \
adrmode(ticks); \
PC= ea; \
if (mpu->callbacks->call[ea]) \
{ \
word addr; \
externalise(); \
if ((addr= mpu->callbacks->call[ea](mpu, ea, 0))) \
{ \
internalise(); \
PC= addr; \
} \
} \
fetch(); \
next();
#define jsr(ticks, adrmode) \
PC++; \
push(PC >> 8); \
push(PC & 0xff); \
PC--; \
adrmode(ticks); \
if (mpu->callbacks->call[ea]) \
{ \
word addr; \
externalise(); \
if ((addr= mpu->callbacks->call[ea](mpu, ea, 0))) \
{ \
internalise(); \
PC= addr; \
fetch(); \
next(); \
} \
} \
PC=ea; \
fetch(); \
next();
#define rts(ticks, adrmode) \
tick(ticks); \
PC = pop(); \
PC |= (pop() << 8); \
PC++; \
fetch(); \
next();
#define brk(ticks, adrmode) \
tick(ticks); \
PC++; \
push(PC >> 8); \
push(PC & 0xff); \
P |= flagB; \
push(P | flagX); \
P |= flagI; \
{ \
word hdlr= getMemory(0xfffe) + (getMemory(0xffff) << 8); \
if (mpu->callbacks->call[hdlr]) \
{ \
word addr; \
externalise(); \
if ((addr= mpu->callbacks->call[hdlr](mpu, PC - 2, 0))) \
{ \
internalise(); \
hdlr= addr; \
} \
} \
PC= hdlr; \
} \
fetch(); \
next();
#define rti(ticks, adrmode) \
tick(ticks); \
P= pop(); \
PC= pop(); \
PC |= (pop() << 8); \
fetch(); \
next();
#define nop(ticks, adrmode) \
fetch(); \
tick(ticks); \
next();
#define ill(ticks, adrmode) \
fetch(); \
tick(ticks); \
fflush(stdout); \
fprintf(stderr, "\nundefined instruction %02X\n", memory[PC-1]); \
return 0;
#define phR(ticks, adrmode, R) \
fetch(); \
tick(ticks); \
push(R); \
next();
#define pha(ticks, adrmode) phR(ticks, adrmode, A)
#define phx(ticks, adrmode) phR(ticks, adrmode, X)
#define phy(ticks, adrmode) phR(ticks, adrmode, Y)
#define php(ticks, adrmode) phR(ticks, adrmode, P | flagX | flagB)
#define plR(ticks, adrmode, R) \
fetch(); \
tick(ticks); \
R= pop(); \
setNZ(R & 0x80, !R); \
next();
#define pla(ticks, adrmode) plR(ticks, adrmode, A)
#define plx(ticks, adrmode) plR(ticks, adrmode, X)
#define ply(ticks, adrmode) plR(ticks, adrmode, Y)
#define plp(ticks, adrmode) \
fetch(); \
tick(ticks); \
P= pop(); \
next();
#define clF(ticks, adrmode, F) \
fetch(); \
tick(ticks); \
P &= ~F; \
next();
#define clc(ticks, adrmode) clF(ticks, adrmode, flagC)
#define cld(ticks, adrmode) clF(ticks, adrmode, flagD)
#define cli(ticks, adrmode) clF(ticks, adrmode, flagI)
#define clv(ticks, adrmode) clF(ticks, adrmode, flagV)
#define seF(ticks, adrmode, F) \
fetch(); \
tick(ticks); \
P |= F; \
next();
#define sec(ticks, adrmode) seF(ticks, adrmode, flagC)
#define sed(ticks, adrmode) seF(ticks, adrmode, flagD)
#define sei(ticks, adrmode) seF(ticks, adrmode, flagI)
#define do_insns(_) \
_(00, brk, implied, 7); _(01, ora, indx, 6); _(02, ill, implied, 2); _(03, ill, implied, 2); \
_(04, tsb, zp, 3); _(05, ora, zp, 3); _(06, asl, zp, 5); _(07, ill, implied, 2); \
_(08, php, implied, 3); _(09, ora, immediate, 3); _(0a, asla,implied, 2); _(0b, ill, implied, 2); \
_(0c, tsb, abs, 4); _(0d, ora, abs, 4); _(0e, asl, abs, 6); _(0f, ill, implied, 2); \
_(10, bpl, relative, 2); _(11, ora, indy, 5); _(12, ora, indzp, 3); _(13, ill, implied, 2); \
_(14, trb, zp, 3); _(15, ora, zpx, 4); _(16, asl, zpx, 6); _(17, ill, implied, 2); \
_(18, clc, implied, 2); _(19, ora, absy, 4); _(1a, ina, implied, 2); _(1b, ill, implied, 2); \
_(1c, trb, abs, 4); _(1d, ora, absx, 4); _(1e, asl, absx, 7); _(1f, ill, implied, 2); \
_(20, jsr, abs, 6); _(21, and, indx, 6); _(22, ill, implied, 2); _(23, ill, implied, 2); \
_(24, bit, zp, 3); _(25, and, zp, 3); _(26, rol, zp, 5); _(27, ill, implied, 2); \
_(28, plp, implied, 4); _(29, and, immediate, 3); _(2a, rola,implied, 2); _(2b, ill, implied, 2); \
_(2c, bit, abs, 4); _(2d, and, abs, 4); _(2e, rol, abs, 6); _(2f, ill, implied, 2); \
_(30, bmi, relative, 2); _(31, and, indy, 5); _(32, and, indzp, 3); _(33, ill, implied, 2); \
_(34, bit, zpx, 4); _(35, and, zpx, 4); _(36, rol, zpx, 6); _(37, ill, implied, 2); \
_(38, sec, implied, 2); _(39, and, absy, 4); _(3a, dea, implied, 2); _(3b, ill, implied, 2); \
_(3c, bit, absx, 4); _(3d, and, absx, 4); _(3e, rol, absx, 7); _(3f, ill, implied, 2); \
_(40, rti, implied, 6); _(41, eor, indx, 6); _(42, ill, implied, 2); _(43, ill, implied, 2); \
_(44, ill, implied, 2); _(45, eor, zp, 3); _(46, lsr, zp, 5); _(47, ill, implied, 2); \
_(48, pha, implied, 3); _(49, eor, immediate, 3); _(4a, lsra,implied, 2); _(4b, ill, implied, 2); \
_(4c, jmp, abs, 3); _(4d, eor, abs, 4); _(4e, lsr, abs, 6); _(4f, ill, implied, 2); \
_(50, bvc, relative, 2); _(51, eor, indy, 5); _(52, eor, indzp, 3); _(53, ill, implied, 2); \
_(54, ill, implied, 2); _(55, eor, zpx, 4); _(56, lsr, zpx, 6); _(57, ill, implied, 2); \
_(58, cli, implied, 2); _(59, eor, absy, 4); _(5a, phy, implied, 3); _(5b, ill, implied, 2); \
_(5c, ill, implied, 2); _(5d, eor, absx, 4); _(5e, lsr, absx, 7); _(5f, ill, implied, 2); \
_(60, rts, implied, 6); _(61, adc, indx, 6); _(62, ill, implied, 2); _(63, ill, implied, 2); \
_(64, stz, zp, 3); _(65, adc, zp, 3); _(66, ror, zp, 5); _(67, ill, implied, 2); \
_(68, pla, implied, 4); _(69, adc, immediate, 3); _(6a, rora,implied, 2); _(6b, ill, implied, 2); \
_(6c, jmp, indirect, 5); _(6d, adc, abs, 4); _(6e, ror, abs, 6); _(6f, ill, implied, 2); \
_(70, bvs, relative, 2); _(71, adc, indy, 5); _(72, adc, indzp, 3); _(73, ill, implied, 2); \
_(74, stz, zpx, 4); _(75, adc, zpx, 4); _(76, ror, zpx, 6); _(77, ill, implied, 2); \
_(78, sei, implied, 2); _(79, adc, absy, 4); _(7a, ply, implied, 4); _(7b, ill, implied, 2); \
_(7c, jmp, indabsx, 6); _(7d, adc, absx, 4); _(7e, ror, absx, 7); _(7f, ill, implied, 2); \
_(80, bra, relative, 2); _(81, sta, indx, 6); _(82, ill, implied, 2); _(83, ill, implied, 2); \
_(84, sty, zp, 2); _(85, sta, zp, 2); _(86, stx, zp, 2); _(87, ill, implied, 2); \
_(88, dey, implied, 2); _(89, bit, immediate, 2); _(8a, txa, implied, 2); _(8b, ill, implied, 2); \
_(8c, sty, abs, 4); _(8d, sta, abs, 4); _(8e, stx, abs, 4); _(8f, ill, implied, 2); \
_(90, bcc, relative, 2); _(91, sta, indy, 6); _(92, sta, indzp, 3); _(93, ill, implied, 2); \
_(94, sty, zpx, 4); _(95, sta, zpx, 4); _(96, stx, zpy, 4); _(97, ill, implied, 2); \
_(98, tya, implied, 2); _(99, sta, absy, 5); _(9a, txs, implied, 2); _(9b, ill, implied, 2); \
_(9c, stz, abs, 4); _(9d, sta, absx, 5); _(9e, stz, absx, 5); _(9f, ill, implied, 2); \
_(a0, ldy, immediate, 3); _(a1, lda, indx, 6); _(a2, ldx, immediate, 3); _(a3, ill, implied, 2); \
_(a4, ldy, zp, 3); _(a5, lda, zp, 3); _(a6, ldx, zp, 3); _(a7, ill, implied, 2); \
_(a8, tay, implied, 2); _(a9, lda, immediate, 3); _(aa, tax, implied, 2); _(ab, ill, implied, 2); \
_(ac, ldy, abs, 4); _(ad, lda, abs, 4); _(ae, ldx, abs, 4); _(af, ill, implied, 2); \
_(b0, bcs, relative, 2); _(b1, lda, indy, 5); _(b2, lda, indzp, 3); _(b3, ill, implied, 2); \
_(b4, ldy, zpx, 4); _(b5, lda, zpx, 4); _(b6, ldx, zpy, 4); _(b7, ill, implied, 2); \
_(b8, clv, implied, 2); _(b9, lda, absy, 4); _(ba, tsx, implied, 2); _(bb, ill, implied, 2); \
_(bc, ldy, absx, 4); _(bd, lda, absx, 4); _(be, ldx, absy, 4); _(bf, ill, implied, 2); \
_(c0, cpy, immediate, 3); _(c1, cmp, indx, 6); _(c2, ill, implied, 2); _(c3, ill, implied, 2); \
_(c4, cpy, zp, 3); _(c5, cmp, zp, 3); _(c6, dec, zp, 5); _(c7, ill, implied, 2); \
_(c8, iny, implied, 2); _(c9, cmp, immediate, 3); _(ca, dex, implied, 2); _(cb, ill, implied, 2); \
_(cc, cpy, abs, 4); _(cd, cmp, abs, 4); _(ce, dec, abs, 6); _(cf, ill, implied, 2); \
_(d0, bne, relative, 2); _(d1, cmp, indy, 5); _(d2, cmp, indzp, 3); _(d3, ill, implied, 2); \
_(d4, ill, implied, 2); _(d5, cmp, zpx, 4); _(d6, dec, zpx, 6); _(d7, ill, implied, 2); \
_(d8, cld, implied, 2); _(d9, cmp, absy, 4); _(da, phx, implied, 3); _(db, ill, implied, 2); \
_(dc, ill, implied, 2); _(dd, cmp, absx, 4); _(de, dec, absx, 7); _(df, ill, implied, 2); \
_(e0, cpx, immediate, 3); _(e1, sbc, indx, 6); _(e2, ill, implied, 2); _(e3, ill, implied, 2); \
_(e4, cpx, zp, 3); _(e5, sbc, zp, 3); _(e6, inc, zp, 5); _(e7, ill, implied, 2); \
_(e8, inx, implied, 2); _(e9, sbc, immediate, 3); _(ea, nop, implied, 2); _(eb, ill, implied, 2); \
_(ec, cpx, abs, 4); _(ed, sbc, abs, 4); _(ee, inc, abs, 6); _(ef, ill, implied, 2); \
_(f0, beq, relative, 2); _(f1, sbc, indy, 5); _(f2, sbc, indzp, 3); _(f3, ill, implied, 2); \
_(f4, ill, implied, 2); _(f5, sbc, zpx, 4); _(f6, inc, zpx, 6); _(f7, ill, implied, 2); \
_(f8, sed, implied, 2); _(f9, sbc, absy, 4); _(fa, plx, implied, 4); _(fb, ill, implied, 2); \
_(fc, ill, implied, 2); _(fd, sbc, absx, 4); _(fe, inc, absx, 7); _(ff, ill, implied, 2);
void M6502_irq(M6502 *mpu)
{
if (!(mpu->registers->p & flagI))
{
mpu->memory[0x0100 + mpu->registers->s--] = (byte)(mpu->registers->pc >> 8);
mpu->memory[0x0100 + mpu->registers->s--] = (byte)(mpu->registers->pc & 0xff);
mpu->memory[0x0100 + mpu->registers->s--] = mpu->registers->p;
mpu->registers->p &= ~flagB;
mpu->registers->p |= flagI;
mpu->registers->pc = M6502_getVector(mpu, IRQ);
}
}
void M6502_nmi(M6502 *mpu)
{
mpu->memory[0x0100 + mpu->registers->s--] = (byte)(mpu->registers->pc >> 8);
mpu->memory[0x0100 + mpu->registers->s--] = (byte)(mpu->registers->pc & 0xff);
mpu->memory[0x0100 + mpu->registers->s--] = mpu->registers->p;
mpu->registers->p &= ~flagB;
mpu->registers->p |= flagI;
mpu->registers->pc = M6502_getVector(mpu, NMI);
}
void M6502_reset(M6502 *mpu)
{
mpu->registers->p &= ~flagD;
mpu->registers->p |= flagI;
mpu->registers->pc = M6502_getVector(mpu, RST);
}
/* the compiler should elminate all call to this function */
static void oops(void)
{
fprintf(stderr, "\noops -- instruction dispatch missing\n");
}
int M6502_run(M6502 *mpu)
{
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
static void *itab[256]= { &&_00, &&_01, &&_02, &&_03, &&_04, &&_05, &&_06, &&_07, &&_08, &&_09, &&_0a, &&_0b, &&_0c, &&_0d, &&_0e, &&_0f,
&&_10, &&_11, &&_12, &&_13, &&_14, &&_15, &&_16, &&_17, &&_18, &&_19, &&_1a, &&_1b, &&_1c, &&_1d, &&_1e, &&_1f,
&&_20, &&_21, &&_22, &&_23, &&_24, &&_25, &&_26, &&_27, &&_28, &&_29, &&_2a, &&_2b, &&_2c, &&_2d, &&_2e, &&_2f,
&&_30, &&_31, &&_32, &&_33, &&_34, &&_35, &&_36, &&_37, &&_38, &&_39, &&_3a, &&_3b, &&_3c, &&_3d, &&_3e, &&_3f,
&&_40, &&_41, &&_42, &&_43, &&_44, &&_45, &&_46, &&_47, &&_48, &&_49, &&_4a, &&_4b, &&_4c, &&_4d, &&_4e, &&_4f,
&&_50, &&_51, &&_52, &&_53, &&_54, &&_55, &&_56, &&_57, &&_58, &&_59, &&_5a, &&_5b, &&_5c, &&_5d, &&_5e, &&_5f,
&&_60, &&_61, &&_62, &&_63, &&_64, &&_65, &&_66, &&_67, &&_68, &&_69, &&_6a, &&_6b, &&_6c, &&_6d, &&_6e, &&_6f,
&&_70, &&_71, &&_72, &&_73, &&_74, &&_75, &&_76, &&_77, &&_78, &&_79, &&_7a, &&_7b, &&_7c, &&_7d, &&_7e, &&_7f,
&&_80, &&_81, &&_82, &&_83, &&_84, &&_85, &&_86, &&_87, &&_88, &&_89, &&_8a, &&_8b, &&_8c, &&_8d, &&_8e, &&_8f,
&&_90, &&_91, &&_92, &&_93, &&_94, &&_95, &&_96, &&_97, &&_98, &&_99, &&_9a, &&_9b, &&_9c, &&_9d, &&_9e, &&_9f,
&&_a0, &&_a1, &&_a2, &&_a3, &&_a4, &&_a5, &&_a6, &&_a7, &&_a8, &&_a9, &&_aa, &&_ab, &&_ac, &&_ad, &&_ae, &&_af,
&&_b0, &&_b1, &&_b2, &&_b3, &&_b4, &&_b5, &&_b6, &&_b7, &&_b8, &&_b9, &&_ba, &&_bb, &&_bc, &&_bd, &&_be, &&_bf,
&&_c0, &&_c1, &&_c2, &&_c3, &&_c4, &&_c5, &&_c6, &&_c7, &&_c8, &&_c9, &&_ca, &&_cb, &&_cc, &&_cd, &&_ce, &&_cf,
&&_d0, &&_d1, &&_d2, &&_d3, &&_d4, &&_d5, &&_d6, &&_d7, &&_d8, &&_d9, &&_da, &&_db, &&_dc, &&_dd, &&_de, &&_df,
&&_e0, &&_e1, &&_e2, &&_e3, &&_e4, &&_e5, &&_e6, &&_e7, &&_e8, &&_e9, &&_ea, &&_eb, &&_ec, &&_ed, &&_ee, &&_ef,
&&_f0, &&_f1, &&_f2, &&_f3, &&_f4, &&_f5, &&_f6, &&_f7, &&_f8, &&_f9, &&_fa, &&_fb, &&_fc, &&_fd, &&_fe, &&_ff };
register void **itabp= &itab[0];
register void *tpc;
//# define begin() fetch(); next()
# define begin() goto *(itabp[memory[PC++]])
# define fetch() tpc= itabp[memory[PC++]]
# define next() if (STEP) { PC--; externalise(); return 1; } goto *tpc
# define dispatch(num, name, mode, cycles) _##num: name(cycles, mode) oops(); next()
# define end()
#else /* (!__GNUC__) || (__STRICT_ANSI__) */
# define begin() for (;;) switch (memory[PC++]) {
# define fetch()
# define next() if (STEP) { externalise(); return 1; } break
# define dispatch(num, name, mode, cycles) case 0x##num: name(cycles, mode); next()
# define end() }
#endif
register byte *memory= mpu->memory;
register word PC;
word ea;
byte A, X, Y, P, S;
M6502_Callback *readCallback= mpu->callbacks->read;
M6502_Callback *writeCallback= mpu->callbacks->write;
unsigned int STEP;
# define internalise() STEP=mpu->flags&M6502_SingleStep; A= mpu->registers->a; X= mpu->registers->x; Y= mpu->registers->y; P= mpu->registers->p; S= mpu->registers->s; PC= mpu->registers->pc
# define externalise() mpu->registers->a= A; mpu->registers->x= X; mpu->registers->y= Y; mpu->registers->p= P; mpu->registers->s= S; mpu->registers->pc= PC
internalise();
begin();
do_insns(dispatch);
end();
# undef begin
# undef internalise
# undef externalise
# undef fetch
# undef next
# undef dispatch
# undef end
(void)oops;
return 0;
}
int M6502_disassemble(M6502 *mpu, word ip, char buffer[64])
{
char *s= buffer;
byte *b= mpu->memory + ip;
switch (b[0])
{
# define _implied return 1;
# define _immediate sprintf(s, "#%02X", b[1]); return 2;
# define _zp sprintf(s, "%02X", b[1]); return 2;
# define _zpx sprintf(s, "%02X,X", b[1]); return 2;
# define _zpy sprintf(s, "%02X,Y", b[1]); return 2;
# define _abs sprintf(s, "%02X%02X", b[2], b[1]); return 3;
# define _absx sprintf(s, "%02X%02X,X", b[2], b[1]); return 3;
# define _absy sprintf(s, "%02X%02X,Y", b[2], b[1]); return 3;
# define _relative sprintf(s, "%04X", ip + 2 + (int8_t)b[1]); return 2;
# define _indirect sprintf(s, "(%02X%02X)", b[2], b[1]); return 3;
# define _indzp sprintf(s, "(%02X)", b[1]); return 2;
# define _indx sprintf(s, "(%02X,X)", b[1]); return 2;
# define _indy sprintf(s, "(%02X),Y", b[1]); return 2;
# define _indabsx sprintf(s, "(%02X%02X,X)", b[2], b[1]); return 3;
# define disassemble(num, name, mode, cycles) case 0x##num: s += sprintf(s, "%s ", #name); _##mode
do_insns(disassemble);
# undef _do
}
return 0;
}
void M6502_dump(M6502 *mpu, char buffer[64])
{
M6502_Registers *r= mpu->registers;
uint8_t p= r->p;
# define P(N,C) (p & (1 << (N)) ? (C) : '-')
sprintf(buffer, "PC=%04X SP=%04X A=%02X X=%02X Y=%02X P=%02X %c%c%c%c%c%c%c%c",
r->pc, 0x0100 + r->s,
r->a, r->x, r->y, r->p,
P(7,'N'), P(6,'V'), P(5,'?'), P(4,'B'), P(3,'D'), P(2,'I'), P(1,'Z'), P(0,'C'));
# undef P
}
static void outOfMemory(void)
{
fflush(stdout);
fprintf(stderr, "\nout of memory\n");
abort();
}
M6502 *M6502_new(M6502_Registers *registers, M6502_Memory memory, M6502_Callbacks *callbacks)
{
M6502 *mpu= calloc(1, sizeof(M6502));
if (!mpu) outOfMemory();
if (!registers) { registers = (M6502_Registers *)calloc(1, sizeof(M6502_Registers)); mpu->flags |= M6502_RegistersAllocated; }
if (!memory ) { memory = (uint8_t *)calloc(1, sizeof(M6502_Memory )); mpu->flags |= M6502_MemoryAllocated; }
if (!callbacks) { callbacks = (M6502_Callbacks *)calloc(1, sizeof(M6502_Callbacks)); mpu->flags |= M6502_CallbacksAllocated; }
if (!registers || !memory || !callbacks) outOfMemory();
mpu->registers = registers;
mpu->memory = memory;
mpu->callbacks = callbacks;
return mpu;
}
void M6502_delete(M6502 *mpu)
{
if (mpu->flags & M6502_CallbacksAllocated) free(mpu->callbacks);
if (mpu->flags & M6502_MemoryAllocated ) free(mpu->memory);
if (mpu->flags & M6502_RegistersAllocated) free(mpu->registers);
free(mpu);
}

76
src/lib6502/lib6502.h Normal file
View File

@ -0,0 +1,76 @@
#ifndef __m6502_h
#define __m6502_h
#include <stdio.h>
#include <stdint.h>
typedef struct _M6502 M6502;
typedef struct _M6502_Registers M6502_Registers;
typedef struct _M6502_Callbacks M6502_Callbacks;
typedef int (*M6502_Callback)(M6502 *mpu, uint16_t address, uint8_t data);
typedef M6502_Callback M6502_CallbackTable[0x10000];
typedef uint8_t M6502_Memory[0x10000];
enum {
M6502_NMIVector= 0xfffa, M6502_NMIVectorLSB= 0xfffa, M6502_NMIVectorMSB= 0xfffb,
M6502_RSTVector= 0xfffc, M6502_RSTVectorLSB= 0xfffc, M6502_RSTVectorMSB= 0xfffd,
M6502_IRQVector= 0xfffe, M6502_IRQVectorLSB= 0xfffe, M6502_IRQVectorMSB= 0xffff
};
struct _M6502_Registers
{
uint8_t a; /* accumulator */
uint8_t x; /* X index register */
uint8_t y; /* Y index register */
uint8_t p; /* processor status register */
uint8_t s; /* stack pointer */
uint16_t pc; /* program counter */
};
struct _M6502_Callbacks
{
M6502_CallbackTable read;
M6502_CallbackTable write;
M6502_CallbackTable call;
};
struct _M6502
{
M6502_Registers *registers;
uint8_t *memory;
M6502_Callbacks *callbacks;
unsigned int flags;
};
enum {
M6502_RegistersAllocated = 1 << 0,
M6502_MemoryAllocated = 1 << 1,
M6502_CallbacksAllocated = 1 << 2,
M6502_SingleStep = 1 << 3
};
extern M6502 *M6502_new(M6502_Registers *registers, M6502_Memory memory, M6502_Callbacks *callbacks);
extern void M6502_reset(M6502 *mpu);
extern void M6502_nmi(M6502 *mpu);
extern void M6502_irq(M6502 *mpu);
extern int M6502_run(M6502 *mpu);
extern int M6502_disassemble(M6502 *mpu, uint16_t addr, char buffer[64]);
extern void M6502_dump(M6502 *mpu, char buffer[64]);
extern void M6502_delete(M6502 *mpu);
#define M6502_getVector(MPU, VEC) \
( ( ((MPU)->memory[M6502_##VEC##VectorLSB]) ) \
| ((MPU)->memory[M6502_##VEC##VectorMSB] << 8) )
#define M6502_setVector(MPU, VEC, ADDR) \
( ( ((MPU)->memory[M6502_##VEC##VectorLSB]= ((uint8_t)(ADDR)) & 0xff) ) \
, ((MPU)->memory[M6502_##VEC##VectorMSB]= (uint8_t)((ADDR) >> 8)) )
#define M6502_getCallback(MPU, TYPE, ADDR) ((MPU)->callbacks->TYPE[ADDR])
#define M6502_setCallback(MPU, TYPE, ADDR, FN) ((MPU)->callbacks->TYPE[ADDR]= (FN))
#endif __m6502_h

View File

@ -0,0 +1 @@
.so man3/lib6502.3

View File

@ -0,0 +1 @@
.so man3/lib6502.3

View File

@ -0,0 +1 @@
.so man3/lib6502.3

View File

@ -0,0 +1 @@
.so man3/lib6502.3

View File

@ -0,0 +1 @@
.so man3/lib6502.3

View File

@ -0,0 +1 @@
.so man3/lib6502.3

View File

@ -0,0 +1 @@
.so man3/lib6502.3

View File

@ -0,0 +1 @@
.so man3/lib6502.3

View File

@ -0,0 +1 @@
.so man3/lib6502.3

View File

@ -0,0 +1 @@
.so man3/lib6502.3

View File

@ -0,0 +1 @@
.so man3/lib6502.3

View File

@ -0,0 +1 @@
.so man3/lib6502.3

508
src/lib6502/man/lib6502.3 Normal file
View File

@ -0,0 +1,508 @@
.\" Copyright (c) 2005 Ian Piumarta
.\"
.\" Permission is hereby granted, free of charge, to any person
.\" obtaining a copy of this software and associated documentation
.\" files (the 'Software'), to deal in the Software without
.\" restriction, including without limitation the rights to use, copy,
.\" modify, merge, publish, distribute, and/or sell copies of the
.\" Software, and to permit persons to whom the Software is furnished
.\" to do so, provided that the above copyright notice(s) and this
.\" permission notice appear in all copies of the Software and that
.\" both the above copyright notice(s) and this permission notice
.\" appear in supporting documentation.
.\"
.\" THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK.
.\"
.\" last edited: 2005-11-02 01:18:07 by piumarta on margaux.local
.\"
.Dd October 31, 2005
.Dt LIB6502 3 LOCAL
.Os ""
.\" ----------------------------------------------------------------
.Sh NAME
.\"
.Nm lib6502
.Nd 6502 microprocessor emulator
.\" ----------------------------------------------------------------
.Sh SYNOPSIS
.\"
.In stdint.h
.In lib6502.h
.Ft M6502 *
.Fn M6502_new "M6502_Registers *registers" "M6502_Memory memory" "M6502_Callbacks *callbacks"
.Ft void
.Fn M6502_reset "M6502 *mpu"
.Ft void
.Fn M6502_nmi "M6502 *mpu"
.Ft void
.Fn M6502_irq "M6502 *mpu"
.Ft uint16_t
.Fn M6502_getVector "M6502 *mpu" "vector"
.Ft uint16_t
.Fn M6502_setVector "M6502 *mpu" "vector" "uint16_t address"
.Ft M6502_Callback
.Fn M6502_getCallback "M6502 *mpu" "type" "uint16_t address"
.Ft M6502_Callback
.Fn M6502_setCallback "M6502 *mpu" "type" "uint16_t address" "M6502_Callback callback"
.Ft void
.Fn M6502_run "M6502 *mpu"
.Ft int
.Fn M6502_disassemble "M6502 *mpu" "uint16_t address" "char buffer[64]"
.Ft void
.Fn M6502_dump "M6502 *mpu" "char buffer[64]"
.Ft void
.Fn M6502_delete "M6502 *mpu"
.\" ----------------------------------------------------------------
.Sh DESCRIPTION
.\"
.Fn M6502_new
creates an instance of a 6502 microprocessor.
.Fn M6502_reset ,
.Fn M6502_nmi
and
.Fn M6502_irq
place it into the states associated with the hardware signals for
reset, non-maskable interrupt and interrupt request, respectively.
The macros
.Fn M6502_getVector
and
.Fn M6502_setVector
read and write the vectors through which the processor jumps in
response to the above signals. The macros
.Fn M6502_getCallback
and
.Fn M6502_setVector
read and write client-supplied functions that intercept accesses to
memory.
.Fn M6502_run
begins emulated execution.
.Fn M6502_dump
and
.Fn M6502_disassemble
create human-readable representations of processor or memory state.
.Fn M6502_delete
frees all resources associated with a processor instance. Each of
these functions and macros is described in more detail below.
.Pp
.Fn M6502_new
returns a pointer to a
.Fa M6502
structure containing at least the following members:
.Bd -literal
struct _M6502
{
M6502_Registers *registers; /* processor state */
uint8_t *memory; /* memory image */
M6502_Callbacks *callbacks; /* r/w/x callbacks */
};
.Ed
.Pp
These members are initialised according to the supplied
.Fa registers ,
.Fa memory
and
.Fa callbacks
arguments. If a given argument is NULL, the corresponding member is
initialised automatically with a suitable (non-NULL) value.
.Pp
The members of
.Fa M6502
are as follows:
.Bl -tag -width ".Fa callbacks"
.It Fa registers
the processor state, containing all registers and condition codes.
.It Fa memory
a block of at least 64 kilobytes of storage containing the processor's
memory. (An array type
.Vt M6502_Memory,
suitable for defining values to pass as the
.Fa memory
argument, is defined in the
.In lib6502.h
include file.)
.It Fa callbacks
a structure mapping processor memory accesses to client callback
functions.
.El
.Pp
Access to the contents of the
.Fa registers
and
.Fa memory
members can be made directly.
The
.Fa registers
member is a
.Vt M6502_Registers
containing the following members:
.Bd -literal
struct _M6502_Registers
{
uint8_t a; /* accumulator */
uint8_t x; /* X index register */
uint8_t y; /* Y index register */
uint8_t p; /* processor status register */
uint8_t s; /* stack pointer */
uint16_t pc; /* program counter */
};
.Ed
.Pp
The
.Fa memory
member is an array of
.Vt unsigned char
and can be indexed directly. In addition, two convenience macros
.Fn M6502_getVector
and
.Fn M6502_setVector
provide access to the reset and interrupt vectors within
.Fa memory .
.Fn M6502_getVector
returns the address stored in the named
.Fa vector
which must be precisely one of the following:
.Bl -tag -width ".Dv RST" -offset indent
.It Dv RST
the reset vector.
.It Dv NMI
the non-maskable interrupt vector.
.It Dv IRQ
the interrupt request vector.
.El
.Pp
.Fn M6502_setVector
stores its
.Fa address
argument in the named
.Fa vector
and returns the new value.
.Pp
The
.Fa callbacks
member contains an opaque structure mapping processor memory accesses
to client callback functions. Whenever the processor performs an
access for which a corresponding entry exists in the the
.Fa callbacks
structure, the emulator suspends execution and invokes the callback to
complete the operation. Each callback function should have a
signature equivalent to:
.Bd -ragged -offset indent
int
.Va callback
(M6502 *mpu, uint16_t address, uint8_t data);
.Ed
.Pp
The macros
.Fn M6502_getCallback
and
.Fn M6502_setCallback
read and write entries in the
.Fa callbacks
structure. These macros identify a unique memory access operation
from the specified
.Fa address
on which it operates and
.Fa type
of access involved. The
.Fa type
argument must be one of the following:
.Bl -tag -width ".Dv write"
.It Dv read
the
.Fa callback
is invoked when the processor attempts to read from the
given address. The emulator passes the effective address of the
operation to the callback in its
.Fa address
argument. (The
.Fa data
argument is undefined.) The value returned by the callback will be
used by the emulator as the result of the read operation.
.It Dv write
the
.Fa callback
is invoked when the processor attempts to write to the
given address. The emulator passes the effective address of the
operation to the callback in its
.Fa address
argument and the byte being written in the
.Fa data
argument. The emulator will not perform the write operation before
invoking the callback; if the write should complete, the callback must
modify the processor's
.Fa memory
explicitly. The valued returned from the callback is ignored.
.It Dv call
the
.Fa callback
is invoked when the processor attempts to transfer control to the
given address by any instruction other than a relative branch. The
emulator passes the destination address to the callback in its
.Fa address
argument and the instruction that initiated the control transfer in
its
.Fa data
argument (one of JMP, JSR, BRK, RTS or RTI). If the callback returns
zero (the callback refuses to handle the operation) the emulator will
allow the operation to complete as normal. If the callback returns a
non-zero address (indicating that the callback has handled the
operation internally) the emulator will transfer control to that
address.
.El
.Pp
.Fn M6502_getCallback
returns zero if there is no callback associated with the given
.Fa type
and
.Fa address .
Passing zero as the
.Fa callback
argument of
.Fn M6502_setCallback
removes any callback that might have been associated with
.Fa type
and
.Fa address .
.Pp
.Fn M6502_run
emulates processor execution in the given
.Fa mpu
by repeatedly fetching the instruction addressed by
.Fa pc
and dispatching to it. This function normally never returns.
.Pp
.Fn M6502_dump
writes a (NUL-terminated) symbolic representation of the processor's
internal state into the supplied
.Fa buffer .
Typical output resembles:
.Bd -literal -offset indent
PC=1010 SP=01FE A=0A X=5B Y=00 P=D1 NV-B---C
.Ed
.Pp
.Fn M6502_disassemble
writes a (NUL-terminated) symbolic representation of the instruction
in the processor's memory at the given
.Fa address
into the supplied
.Fa buffer .
It returns the size (in bytes) of the instruction. (In other words,
the amount by which
.Fa address
should be incremented to arrive at the next instruction.)
Typical output resembles:
.Bd -literal -offset indent
1009 cpx #5B
.Ed
.Pp
(The
.Fa buffer
arguments are oversized to allow for future expansion.)
.Pp
.Fn M6502_delete
frees the resources associated with the given
.Fa mpu.
Any members that were allocated implicitly (passed as NULL to
.Fn M6502_new )
are deallocated. Members that were initialised from non-NULL
arguments are not deallocated.
.\" ----------------------------------------------------------------
.Sh IMPLEMENTATION NOTES
.\"
You can share the
.Fa memory
and
.Fa callbacks
members of
.Vt M6502
between multiple instances to simulate multiprocessor hardware.
.\" ----------------------------------------------------------------
.Sh RETURN VALUES
.\"
.Fn M6502_new
returns a pointer to a
.Vt M6502
structure.
.Fn M6502_getVector
and
.Fn M6502_setVector
return the contents of the given
.Fa vector .
.Fn M6502_getCallback
and
.Fn M6502_setCallback
return the
.Vt M6502_Callback
function associated with the given
.Fa address
and access
.Fa type .
.Fn M6502_disassemble
returns the size (in bytes) of the instruction at the given
.Fa address .
.Fn M6502_reset ,
.Fn M6502_nmi ,
.Fn M6502_irq ,
.Fn M6502_run ,
.Fn M6502_dump
and
.Fn M6502_delete
don't return anything (unless you forgot to include
.In lib6502.h ) .
.\" ----------------------------------------------------------------
.Sh EXAMPLES
.\"
The following program creates a 6502 processor, sets up callbacks for
printing characters and halting after a BRK instruction, stores a
program into memory that prints the alphabet, disassembles the program
on stdout, and then executes the program.
.Bd -literal -offset indent -compact
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include "lib6502.h"
#define WRCH 0xFFEE
int wrch(M6502 *mpu, uint16_t address, uint8_t data)
{
int pc;
putchar(mpu->registers->a);
pc = mpu->memory[++mpu->registers->s + 0x100];
pc |= mpu->memory[++mpu->registers->s + 0x100] << 8;
return pc + 1; /* JSR pushes next insn addr - 1 */
}
int done(M6502 *mpu, uint16_t address, uint8_t data)
{
char buffer[64];
M6502_dump(mpu, buffer);
printf("\\nBRK instruction\\n%s\\n", buffer);
exit(0);
}
int main(int argc, char **argv)
{
M6502 *mpu = M6502_new(0, 0, 0);
unsigned pc = 0x1000;
mpu->callbacks->call[WRCH] = wrch; /* write character */
mpu->callbacks->call[0000] = done; /* reached after BRK */
# define gen1(X) (mpu->memory[pc++] = (uint8_t)(X))
# define gen2(X,Y) gen1(X); gen1(Y)
# define gen3(X,Y,Z) gen1(X); gen2(Y,Z)
gen2(0xA2, 'A' ); /* LDX #'A' */
gen1(0x8A ); /* TXA */
gen3(0x20,0xEE,0xFF); /* JSR FFEE */
gen1(0xE8 ); /* INX */
gen2(0xE0, 'Z'+1 ); /* CPX #'Z'+1 */
gen2(0xD0, -9 ); /* BNE 1002 */
gen2(0xA9, '\\n' ); /* LDA #'\\n' */
gen3(0x20,0xEE,0xFF); /* JSR FFEE */
gen2(0x00,0x00 ); /* BRK */
{
uint16_t ip = 0x1000;
while (ip < pc)
{
char insn[64];
ip += M6502_disassemble(mpu, ip, insn);
printf("%04X %s\\n", ip, insn);
}
}
M6502_setVector(mpu, RST, 0x1000);
M6502_reset(mpu);
M6502_run(mpu);
M6502_delete(mpu);
return 0;
}
.Ed
.\" ----------------------------------------------------------------
.Sh DIAGNOSTICS
.\"
If
.Fn M6502_new
cannot allocate sufficient memory it prints "out of memory" to stderr
and exits with a non-zero status.
.Pp
If
.Fn M6502_run
encounters an illegal or undefined instruction, it prints "undefined
instruction" and the processor's state to stderr, then exits with a
non-zero status.
.\" ----------------------------------------------------------------
.Sh COMPATIBILITY
.\"
M6502 is a generic name. The initial letter is mandated by C naming
conventions and chosen in deference to MOS Technology, the original
designers of the processor. To the best of my knowledge the 'M'
prefix was never stamped on a physical 6502.
.Pp
The emulator implements the CMOS version of the processor (NMOS bugs
in effective address calculations involving page boundaries are
corrected) but does not tolerate the execution of undefined
instructions (which were all no-ops in the first-generation CMOS
hardware). It would be nice to support the several alternative
instruction sets (model-specific undocumented instructions in NMOS
models, and various documented extensions in the later CMOS models)
but there are currently no plans to do so.
.Pp
The emulated 6502 will run much faster than real hardware on any
modern computer. The fastest 6502 hardware available at the time of
writing has a clock speed of 14 MHz. On a 2 GHz PowerPC, the emulated
6502 runs at almost 300 MHz.
.\" ----------------------------------------------------------------
.Sh SEE ALSO
.\"
.Xr run6502 1
.Pp
For development tools, documentation and source code:
.Pa http://6502.org
.\" ----------------------------------------------------------------
.Sh AUTHORS
.\"
The software and manual pages were written by Ian Piumarta.
.Pp
The software is provided as-is, with absolutely no warranty, in the
hope that you will enjoy and benefit from it. You may use (entirely
at your own risk) and redistribute it under the terms of a very
liberal license that does not seek to restrict your rights in any way
(unlike certain so-called 'open source' licenses that significantly
limit your freedom in the name of 'free' software that is, ultimately,
anything but free). See the file COPYING for details.
.\" ----------------------------------------------------------------
.Sh BUGS
.\"
.Fn M6502_getVector
and
.Fn M6502_setVector
evaluate their arguments more than once.
.Pp
The out-of-memory condition and attempted execution of
illegal/undefined instructions should not be fatal errors.
.Pp
There is no way to limit the duration of execution within
.Fn M6502_run
to a certain number of instructions or cycles.
.Pp
The emulator should support some means of implicit interrupt
generation, either by polling or in response to (Unix) signals.
.Pp
The
.Sx COMPATIBILITY
section in this manual page has been diverted from its legitimate
purpose.
.Pp
The plural of 'callback' really aught to be 'callsback'.
.Pp
Please send bug reports (and feature requests) to the author at:
firstName (at) lastName (dot) com. (See
.Sx AUTHORS
above for suitable values of firstName and lastName.)

380
src/lib6502/man/run6502.1 Normal file
View File

@ -0,0 +1,380 @@
.\" Copyright (c) 2005 Ian Piumarta
.\"
.\" Permission is hereby granted, free of charge, to any person
.\" obtaining a copy of this software and associated documentation
.\" files (the 'Software'), to deal in the Software without
.\" restriction, including without limitation the rights to use, copy,
.\" modify, merge, publish, distribute, and/or sell copies of the
.\" Software, and to permit persons to whom the Software is furnished
.\" to do so, provided that the above copyright notice(s) and this
.\" permission notice appear in all copies of the Software and that
.\" both the above copyright notice(s) and this permission notice
.\" appear in supporting documentation.
.\"
.\" THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK.
.\"
.\" last edited: 2005-11-02 01:18:22 by piumarta on margaux.local
.\"
.Dd October 31, 2005
.Dt RUN6502 1 LOCAL
.Os ""
.\" ----------------------------------------------------------------
.Sh NAME
.\"
.Nm run6502
.Nd execute a 6502 microprocessor program
.\" ----------------------------------------------------------------
.Sh SYNOPSIS
.\"
.Nm run6502
.Op Ar option ...
.Nm run6502
.Op Ar option ...
.Fl B
.Op Ar
.\" ----------------------------------------------------------------
.Sh DESCRIPTION
The
.Nm run6502
command emulates the execution of a 6502 microprocessor. It creates a
memory image from the contents of one or more files on the command
line and then simulates a power-on hardware reset to begin execution.
.Pp
In its first form,
.Nm run6502
emulates an embedded 6502 processor with 64 kilobytes of RAM, no
memory-mapped hardware, and no input-output capabilities. Limited
interaction with the machine is possible only through the
.Fl G , M
and
.Fl P
options.
.Pp
In its second form (with the
.Fl B
option)
.Nm run6502
provides minimal emulation of Acorn 'BBC Model B' hardware with 32
kilobytes of RAM, 16 kilobytes of paged language ROMs, and 16
kilobytes of operating system ROM. A few MOS calls are intercepted to
provide keyboard input and screen output via stdin and stdout.
Switching between the sixteen paged read-only memory banks is also
supported by the usual memory-mapped control register. Any
.Ar file
arguments after the
.Fl B
are loaded into successive paged ROM banks (starting at 15 and working
down towards 0) before execution begins.
.\" ----------------------------------------------------------------
.Ss Options
.\"
.Bl -tag -width indent
.It Fl B
enable minimal Acorn 'BBC Model B' hardware emulation:
.Bl -bullet
.It
the contents of memory between addresses 0x8000 and 0xBFFF are copied
into paged ROM number 0;
.It
memory between 0x8000 and 0xBFFF becomes bank-switchable between
sixteen different ROM images;
.It
the memory-mapped pages ('FRED', 'JIM' and 'SHEILA') between 0xFC00
and 0xFEFF are initialised to harmless values;
.It
the upper half of the address space is write-protected; and
.It
callbacks are installed on several OS entry points to provide
input-output via stdin and stdout.
.El
.Pp
Any remaining non-option arguments on the command line will name files
to be loaded successively into paged ROMs, starting at 15 and working
downwards towards 0.
.It Fl d Ar addr Ar end
dump memory from the address
.Ar addr
(given in hexadecimal) up to (but not including)
.Ar end .
The
.Ar end
argument is either an absolute address or a relative address specified
as a '+' character followed by the number (in hexadecimal) of bytes to
dump. In other words, the following two options dump the same region
of memory:
.Bd -ragged -offset indent
.Fl d
8000 C000
.Ed
.Bd -ragged -offset indent -compact
.Fl d
8000 +4000
.Ed
.Pp
The format of the dump cannot currently be modified and consists of
the current address followed by one, two or three hexadecimal bytes,
and a symbolic representation of the instruction at that address.
.It Fl G Ar addr
arrange that subroutine calls to
.Ar addr
will behave as if there were an implementation of
.Xr getchar 3
at that address, reading a character from stdin and returning it in
the accumulator.
.It Fl h
print a summary of the available options and then exit.
.It Fl I Ar addr
set the IRQ (interrupt request) vector (the address to which the
processor will transfer control upon execution of a BRK instruction).
Setting this address to zero will cause execution to halt (and the
emulator to exit) when a BRK instruction is encountered.
.It Fl i Ar addr Ar file
Load
.Ar file
into the memory image at the address
.Ar addr
(in hexadecimal), skipping over any initial '#!' interpreter line.
.It Fl l Ar addr Ar file
Load
.Ar file
into the memory image at the address
.Ar addr
(in hexadecimal).
.It Fl M Ar addrio
arrange that memory reads from address
.Ar addrio
will return the next character on stdin (blocking if necessary), and
memory writes to
.Ar addrio
will send the value written to stdout.
.It Fl N Ar addr
set the NMI (non-maskable interrupt) vector to
.Ar addr .
.It Fl P Ar addr
arrange that subroutine calls to
.Ar addr
will behave as if there were an implementation of
.Xr putchar 3
at that address, writing the contents of the accumulator to stdout.
.It Fl R Ar addr
set the RST (hardware reset) vector. The processor will transfer
control to this address when emulated execution begins.
.It Fl s Ar addr Ar end Ar file
save the contents of memory from the address
.Ar addr
up to
.Ar end
(exclusive) to the given
.Ar file .
As with the
.Fl d
option,
.Ar end
can be absolute or '+' followed by a byte count.
.It Fl v
print version information and then exit.
.It Fl X Ar addr
arrange that any transfer of control to the address
.Ar addr
will cause an immediate exit with zero exit status.
.It Fl x
exit immediately. (Useful after
.Fl d
or when
.Nm run6502
is being used as a trivial 'image editor', with several
.Fl l
options followed by
.Fl s
and
.Fl x . )
.It Ar
following a
.Fl B
option, load one or more ROM image
files
into successive paged ROM slots. Other than the paging aspect, this
is equivalent to:
.Bd -ragged -offset indent
.Fl l Ar 8000 Ar image
.Ed
.El
.\" ----------------------------------------------------------------
.Sh EXAMPLES
.\"
.Ss A Very Simple Program
The
.Xr perl 1
command can be used to create a binary file from hexadecimal input:
.Bd -literal
echo a2418a20eeffe8e05bd0f7a90a20eeff00 |
perl -e 'print pack "H*",<STDIN>' > temp.img
.Ed
.Pp
The file can be loaded and executed with:
.Bd -literal
run6502 -l 1000 temp.img -R 1000 -P FFEE -X 0
.Ed
.Pp
The contents of the file can be inspected symbolically with:
.Bd -literal
run6502 -l 1000 temp.img -d 1000 +12
.Ed
.Pp
The options passed to
.Nm run6502
in the above examples have the following effects:
.Bl -tag -width offset
.It \-l 1000 temp.img
loads the file
.Pa temp.img
into memory at address 0x8000.
.It \-R 1000
sets the reset vector (the address of first instruction to be executed
after 'power on') to 0x1000.
.It \-P FFEE
arranges for calls to address 0xFFEE to behave as if there were an
implementation of
.Xr putchar 3
at that address.
.It \-X 0
arranges for transfers of control to address 0 to exit from the
emulator. This works in the above example because the final 'BRK'
instruction causes an implicit subroutine call through an
uninitialised interrupt vector to location 0. To see this
instruction...
.It \-d 1000 +12
disassembles 18 bytes of memory at address 0x8000.
.El
.Ss Standalone Images
The
.Fl i
option is designed for use in the 'interpreter command' appearing on
the first line of an executable script. Adding the line
.Bd -literal
#!run6502 -R 1000 -P FFEE -X 0 -i 1000
.Ed
.Pp
(with no leading spaces and a single trailing newline character)
to the
.Pa temp.img
file from the first example turns it into a script. If the file is
made executable with
.Bd -literal
chmod +x temp.img
.Ed
.Pp
it can be run like a standalone program:
.Bd -literal
./temp.img
.Ed
.Ss A Very Complex Program
Consider a pair of files named
.Pa os1.2
and
.Pa basic2
containing (legally-acquired, of course) ROM images of Acorn MOS 1.2
and BBC Basic 2. The following command loads each of the images into
memory at the appropriate address, cleans up the regions of memory
containing memory-mapped i/o on the BBC computer, saves a snapshot of
the entire memory to the file
.Pa image
and then exits:
.Bd -literal
run6502 -l C000 os1.2 -l 8000 basic2 -B -s0 +10000 image -x
.Ed
.Pp
Running the generated image with
.Bd -literal
run6502 image
.Ed
.Pp
will cold-start the emulated hardware, run the OS for a while, and
then drop into the language ROM. Basic programs can then be entered,
edited and run from the terminal.
.Pp
More details are given in the
.Pa README
file available in the
.Pa examples
directory of the distribution.
.Ss Exercises
Create a standalone image (one that can be run as a program, with
a '#!' interpreter line at the beginning) that contains Basic2 and
OS1.2 (as described above). This image should be no larger than 32K
(memory below 0x8000, which would be full of zeroes, should not appear
in the image file).
.\" ----------------------------------------------------------------
.Sh DIAGNOSTICS
.\"
If nothing goes wrong, none. Otherwise lots. They should be
self-explanatory. I'm too lazy to enumerate them.
.\" ----------------------------------------------------------------
.Sh COMPATIBILITY
.\"
See
.Xr lib6502 3
for a discussion of the emulated instruction set.
.\" ----------------------------------------------------------------
.Sh SEE ALSO
.\"
.Xr lib6502 3
.Pp
The file
.Pa examples/README
in the lib6502 distribution. (Depending on your system this may be
installed in
.Pa /usr/doc/lib6502 ,
.Pa /usr/local/doc/lib6502 ,
.Pa /usr/share/doc/lib6502 ,
or similar.)
.Pp
.Pa http://piumarta.com/software/lib6502
for updates and documentation.
.Pp
.Pa http://6502.org
for lots of 6502-related resources.
.\" ----------------------------------------------------------------
.Sh AUTHORS
.\"
The software and manual pages were written by
.An "Ian Piumarta" .
.Pp
The software is provided as-is, with absolutely no warranty, in the
hope that you will enjoy and benefit from it. You may use (entirely
at your own risk) and redistribute it under the terms of a very
liberal license that does not seek to restrict your rights in any way
(unlike certain so-called 'open source' licenses that significantly
limit your freedom in the name of 'free' software that is, ultimately,
anything but free). See the file COPYING for details.
.\" ----------------------------------------------------------------
.Sh BUGS
.\"
.Bl -bullet
.It
Options must appear one at a time.
.It
Any attempt (in a load or save operation) to transfer data beyond
0xFFFF is silently truncated at the end of memory.
.It
There is no way to specify the slot into which a ROM image should be
loaded, other than implicitly according to the order of arguments on
the command line.
.It
Execution can only be started via the emulated power-up reset. There
is no support for 'warm-starting' execution in an image at an
arbitrary address.
.It
Even though the emulator fully supports them, there is no way to
artificially generate a hardware interrupt request, non-maskable
interrupt, or reset condition. If you need these, read
.Xr lib6502 3
and write your own shell.
.It
The Acorn 'BBC Model B' hardware emulation is totally lame.
.El
.Pp
Please send bug reports (and feature requests) to the author at:
firstName (at) lastName (dot) com. (See
.Sx AUTHORS
above for suitable values of firstName and lastName.)

520
src/lib6502/run6502.c Normal file
View File

@ -0,0 +1,520 @@
/* run6502.c -- 6502 emulator shell -*- C -*- */
/* Copyright (c) 2005 Ian Piumarta
*
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the 'Software'),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, provided that the above copyright notice(s) and this
* permission notice appear in all copies of the Software and that both the
* above copyright notice(s) and this permission notice appear in supporting
* documentation.
*
* THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK.
*/
/* Last edited: 2005-11-02 01:18:58 by piumarta on margaux.local
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include "config.h"
#include "lib6502.h"
#define VERSION PACKAGE_NAME " " PACKAGE_VERSION " " PACKAGE_COPYRIGHT
typedef uint8_t byte;
typedef uint16_t word;
static char *program= 0;
static byte bank[0x10][0x4000];
void fail(const char *fmt, ...)
{
va_list ap;
fflush(stdout);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
exit(1);
}
void pfail(const char *msg)
{
fflush(stdout);
perror(msg);
exit(1);
}
#define rts \
{ \
word pc; \
pc = mpu->memory[++mpu->registers->s + 0x100]; \
pc |= mpu->memory[++mpu->registers->s + 0x100] << 8; \
return pc + 1; \
}
int osword(M6502 *mpu, word address, byte data)
{
byte *params= mpu->memory + mpu->registers->x + (mpu->registers->y << 8);
switch (mpu->registers->a)
{
case 0x00: /* input line */
/* On entry: XY+0,1=>string area,
* XY+2=maximum line length,
* XY+3=minimum acceptable ASCII value,
* XY+4=maximum acceptable ASCII value.
* On exit: Y is the line length (excluding CR),
* C is set if Escape terminated input.
*/
{
word offset= params[0] + (params[1] << 8);
byte *buffer= mpu->memory + offset;
byte length= params[2], minVal= params[3], maxVal= params[4], b= 0;
if (!fgets(buffer, length, stdin))
{
putchar('\n');
exit(0);
}
for (b= 0; b < length; ++b)
if ((buffer[b] < minVal) || (buffer[b] > maxVal) || ('\n' == buffer[b]))
break;
buffer[b]= 13;
mpu->registers->y= b;
mpu->registers->p &= 0xFE;
break;
}
default:
{
char state[64];
M6502_dump(mpu, state);
fflush(stdout);
fprintf(stderr, "\nOSWORD %s\n", state);
fail("ABORT");
}
break;
}
rts;
}
int osbyte(M6502 *mpu, word address, byte data)
{
switch (mpu->registers->a)
{
case 0x7A: /* perform keyboard scan */
mpu->registers->x= 0x00;
break;
case 0x7E: /* acknowledge detection of escape condition */
return 1;
break;
case 0x82: /* read machine higher order address */
mpu->registers->y= 0x00;
mpu->registers->x= 0x00;
break;
case 0x83: /* read top of OS ram address (OSHWM) */
mpu->registers->y= 0x0E;
mpu->registers->x= 0x00;
break;
case 0x84: /* read bottom of display ram address */
mpu->registers->y= 0x80;
mpu->registers->x= 0x00;
break;
case 0x89: /* motor control */
break;
case 0xDA: /* read/write number of items in vdu queue (stored at 0x026A) */
return 0;
break;
default:
{
char state[64];
M6502_dump(mpu, state);
fflush(stdout);
fprintf(stderr, "\nOSBYTE %s\n", state);
fail("ABORT");
}
break;
}
rts;
}
int oscli(M6502 *mpu, word address, byte data)
{
byte *params= mpu->memory + mpu->registers->x + (mpu->registers->y << 8);
char command[1024], *ptr= command;
while (('*' == *params) || (' ' == *params))
++params;
while (13 != *params)
*ptr++= *params++;
*ptr= '\0';
system(command);
rts;
}
int oswrch(M6502 *mpu, word address, byte data)
{
switch (mpu->registers->a)
{
case 0x0C:
fputs("\033[2J\033[H", stdout);
break;
default:
putchar(mpu->registers->a);
break;
}
fflush(stdout);
rts;
}
static int writeROM(M6502 *mpu, word address, byte value)
{
return 0;
}
static int bankSelect(M6502 *mpu, word address, byte value)
{
memcpy(mpu->memory + 0x8000, bank[value & 0x0F], 0x4000);
return 0;
}
static int doBtraps(int argc, char **argv, M6502 *mpu)
{
unsigned addr;
/* Acorn Model B ROM and memory-mapped IO */
for (addr= 0x8000; addr <= 0xFBFF; ++addr) mpu->callbacks->write[addr]= writeROM;
for (addr= 0xFC00; addr <= 0xFEFF; ++addr) mpu->memory[addr]= 0xFF;
for (addr= 0xFE30; addr <= 0xFE33; ++addr) mpu->callbacks->write[addr]= bankSelect;
for (addr= 0xFE40; addr <= 0xFE4F; ++addr) mpu->memory[addr]= 0x00;
for (addr= 0xFF00; addr <= 0xFFFF; ++addr) mpu->callbacks->write[addr]= writeROM;
/* anything already loaded at 0x8000 appears in bank 0 */
memcpy(bank[0x00], mpu->memory + 0x8000, 0x4000);
/* fake a few interesting OS calls */
# define trap(vec, addr, func) mpu->callbacks->call[addr]= (func)
trap(0x020C, 0xFFF1, osword);
trap(0x020A, 0xFFF4, osbyte);
//trap(0x0208, 0xFFF7, oscli ); /* enable this to send '*COMMAND's to system(3) :-) */
trap(0x020E, 0xFFEE, oswrch);
trap(0x020E, 0xE0A4, oswrch); /* NVWRCH */
#undef trap
return 0;
}
static void usage(int status)
{
FILE *stream= status ? stderr : stdout;
fprintf(stream, VERSION"\n");
fprintf(stream, "please send bug reports to: %s\n", PACKAGE_BUGREPORT);
fprintf(stream, "\n");
fprintf(stream, "usage: %s [option ...]\n", program);
fprintf(stream, " %s [option ...] -B [image ...]\n", program);
fprintf(stream, " -B -- minimal Acorn 'BBC Model B' compatibility\n");
fprintf(stream, " -d addr last -- dump memory between addr and last\n");
fprintf(stream, " -G addr -- emulate getchar(3) at addr\n");
fprintf(stream, " -h -- help (print this message)\n");
fprintf(stream, " -I addr -- set IRQ vector\n");
fprintf(stream, " -l addr file -- load file at addr\n");
fprintf(stream, " -M addr -- emulate memory-mapped stdio at addr\n");
fprintf(stream, " -N addr -- set NMI vector\n");
fprintf(stream, " -P addr -- emulate putchar(3) at addr\n");
fprintf(stream, " -R addr -- set RST vector\n");
fprintf(stream, " -s addr last file -- save memory from addr to last in file\n");
fprintf(stream, " -v -- print version number then exit\n");
fprintf(stream, " -X addr -- terminate emulation if PC reaches addr\n");
fprintf(stream, " -x -- exit wihout further ado\n");
fprintf(stream, " image -- '-l 8000 image' in available ROM slot\n");
fprintf(stream, "\n");
fprintf(stream, "'last' can be an address (non-inclusive) or '+size' (in bytes)\n");
exit(status);
}
static int doHelp(int argc, char **argv, M6502 *mpu)
{
usage(0);
return 0;
}
static int doVersion(int argc, char **argv, M6502 *mpu)
{
puts(VERSION);
exit(0);
return 0;
}
static unsigned long htol(char *hex)
{
char *end;
unsigned long l= strtol(hex, &end, 16);
if (*end) fail("bad hex number: %s", hex);
return l;
}
static int loadInterpreter(M6502 *mpu, word start, const char *path)
{
FILE *file= 0;
int count= 0;
byte *memory= mpu->memory + start;
size_t max= 0x10000 - start;
int c= 0;
if ((!(file= fopen(path, "r"))) || ('#' != fgetc(file)) || ('!' != fgetc(file)))
return 0;
while ((c= fgetc(file)) >= ' ')
;
while ((count= fread(memory, 1, max, file)) > 0)
{
memory += count;
max -= count;
}
fclose(file);
return 1;
}
static int save(M6502 *mpu, word address, unsigned length, const char *path)
{
FILE *file= 0;
int count= 0;
if (!(file= fopen(path, "w")))
return 0;
while ((count= fwrite(mpu->memory + address, 1, length, file)))
{
address += count;
length -= count;
}
fclose(file);
return 1;
}
static int load(M6502 *mpu, word address, const char *path)
{
FILE *file= 0;
int count= 0;
size_t max= 0x10000 - address;
if (!(file= fopen(path, "r")))
return 0;
while ((count= fread(mpu->memory + address, 1, max, file)) > 0)
{
address += count;
max -= count;
}
fclose(file);
return 1;
}
static int doLoadInterpreter(int argc, char **argv, M6502 *mpu)
{
if (argc < 3) usage(1);
if (!loadInterpreter(mpu, htol(argv[1]), argv[2])) pfail(argv[2]);
return 2;
}
static int doLoad(int argc, char **argv, M6502 *mpu) /* -l addr file */
{
if (argc < 3) usage(1);
if (!load(mpu, htol(argv[1]), argv[2])) pfail(argv[2]);
return 2;
}
static int doSave(int argc, char **argv, M6502 *mpu) /* -l addr size file */
{
if (argc < 4) usage(1);
if (!save(mpu, htol(argv[1]), htol(argv[2]), argv[3])) pfail(argv[3]);
return 3;
}
#define doVEC(VEC) \
static int do##VEC(int argc, char **argv, M6502 *mpu) \
{ \
unsigned addr= 0; \
if (argc < 2) usage(1); \
addr= htol(argv[1]); \
M6502_setVector(mpu, VEC, addr); \
return 1; \
}
doVEC(IRQ);
doVEC(NMI);
doVEC(RST);
#undef doVEC
static int gTrap(M6502 *mpu, word addr, byte data) { mpu->registers->a= getchar(); rts; }
static int pTrap(M6502 *mpu, word addr, byte data) { putchar(mpu->registers->a); rts; }
static int doGtrap(int argc, char **argv, M6502 *mpu)
{
unsigned addr;
if (argc < 2) usage(1);
addr= htol(argv[1]);
M6502_setCallback(mpu, call, addr, gTrap);
return 1;
}
static int doPtrap(int argc, char **argv, M6502 *mpu)
{
unsigned addr;
if (argc < 2) usage(1);
addr= htol(argv[1]);
M6502_setCallback(mpu, call, addr, pTrap);
return 1;
}
static int mTrapRead(M6502 *mpu, word addr, byte data) { return getchar(); }
static int mTrapWrite(M6502 *mpu, word addr, byte data) { return putchar(data); }
static int doMtrap(int argc, char **argv, M6502 *mpu)
{
unsigned addr= 0;
if (argc < 2) usage(1);
addr= htol(argv[1]);
M6502_setCallback(mpu, read, addr, mTrapRead);
M6502_setCallback(mpu, write, addr, mTrapWrite);
return 1;
}
static int xTrap(M6502 *mpu, word addr, byte data) { exit(0); return 0; }
static int doXtrap(int argc, char **argv, M6502 *mpu)
{
unsigned addr= 0;
if (argc < 2) usage(1);
addr= htol(argv[1]);
M6502_setCallback(mpu, call, addr, xTrap);
return 1;
}
static int doDisassemble(int argc, char **argv, M6502 *mpu)
{
unsigned addr= 0, last= 0;
if (argc < 3) usage(1);
addr= htol(argv[1]);
last= ('+' == *argv[2]) ? addr + htol(1 + argv[2]) : htol(argv[2]);
while (addr < last)
{
char insn[64];
int i= 0, size= M6502_disassemble(mpu, addr, insn);
printf("%04X ", addr);
while (i++ < size) printf("%02X", mpu->memory[addr + i - 1]);
while (i++ < 4) printf(" ");
putchar(' ');
i= 0;
while (i++ < size) putchar(isgraph(mpu->memory[addr + i - 1]) ? mpu->memory[addr + i - 1] : ' ');
while (i++ < 4) putchar(' ');
printf(" %s\n", insn);
addr += size;
}
return 2;
}
int main(int argc, char **argv)
{
M6502 *mpu= M6502_new(0, 0, 0);
int bTraps= 0;
program= argv[0];
if ((2 == argc) && ('-' != *argv[1]))
{
if ((!loadInterpreter(mpu, 0, argv[1])) && (!load(mpu, 0, argv[1])))
pfail(argv[1]);
doBtraps(0, 0, mpu);
}
else
while (++argv, --argc > 0)
{
int n= 0;
if (!strcmp(*argv, "-B")) bTraps= 1;
else if (!strcmp(*argv, "-d")) n= doDisassemble(argc, argv, mpu);
else if (!strcmp(*argv, "-G")) n= doGtrap(argc, argv, mpu);
else if (!strcmp(*argv, "-h")) n= doHelp(argc, argv, mpu);
else if (!strcmp(*argv, "-i")) n= doLoadInterpreter(argc, argv, mpu);
else if (!strcmp(*argv, "-I")) n= doIRQ(argc, argv, mpu);
else if (!strcmp(*argv, "-l")) n= doLoad(argc, argv, mpu);
else if (!strcmp(*argv, "-M")) n= doMtrap(argc, argv, mpu);
else if (!strcmp(*argv, "-N")) n= doNMI(argc, argv, mpu);
else if (!strcmp(*argv, "-P")) n= doPtrap(argc, argv, mpu);
else if (!strcmp(*argv, "-R")) n= doRST(argc, argv, mpu);
else if (!strcmp(*argv, "-s")) n= doSave(argc, argv, mpu);
else if (!strcmp(*argv, "-v")) n= doVersion(argc, argv, mpu);
else if (!strcmp(*argv, "-X")) n= doXtrap(argc, argv, mpu);
else if (!strcmp(*argv, "-x")) exit(0);
else if ('-' == **argv) usage(1);
else
{
/* doBtraps() left 0x8000+0x4000 in bank 0, so load */
/* additional images starting at 15 and work down */
static int bankSel= 0x0F;
if (!bTraps) usage(1);
if (bankSel < 0) fail("too many images");
if (!load(mpu, 0x8000, argv[0])) pfail(argv[0]);
memcpy(bank[bankSel--],
0x8000 + mpu->memory,
0x4000);
n= 1;
}
argc -= n;
argv += n;
}
if (bTraps)
doBtraps(0, 0, mpu);
M6502_reset(mpu);
M6502_run(mpu);
M6502_delete(mpu);
return 0;
}

View File

@ -0,0 +1,277 @@
include "inc/cmdsys.plh"
include "inc/lines.plh"
sysflags resxtxt1|reshgr1|resxhgr1
//
// Apple II graphics soft switches
//
const store80dis = $C000
const store80ena = $C001
const show40col = $C00C
const show80col = $C00D
const showgraphics = $C050
const showtext = $C051
const showfull = $C052
const showmix = $C053
const page1m = $C054
const page1x = $C055
const showhires = $C057
const dhresena = $C05E
const dhresdis = $C05F
const IOUdis = $C07E
const IOUena = $C07F
//
// HiRes scanline addresses
//
word hgrscan[] = $2000,$2400,$2800,$2C00,$3000,$3400,$3800,$3C00
word = $2080,$2480,$2880,$2C80,$3080,$3480,$3880,$3C80
word = $2100,$2500,$2900,$2D00,$3100,$3500,$3900,$3D00
word = $2180,$2580,$2980,$2D80,$3180,$3580,$3980,$3D80
word = $2200,$2600,$2A00,$2E00,$3200,$3600,$3A00,$3E00
word = $2280,$2680,$2A80,$2E80,$3280,$3680,$3A80,$3E80
word = $2300,$2700,$2B00,$2F00,$3300,$3700,$3B00,$3F00
word = $2380,$2780,$2B80,$2F80,$3380,$3780,$3B80,$3F80
word = $2028,$2428,$2828,$2C28,$3028,$3428,$3828,$3C28
word = $20A8,$24A8,$28A8,$2CA8,$30A8,$34A8,$38A8,$3CA8
word = $2128,$2528,$2928,$2D28,$3128,$3528,$3928,$3D28
word = $21A8,$25A8,$29A8,$2DA8,$31A8,$35A8,$39A8,$3DA8
word = $2228,$2628,$2A28,$2E28,$3228,$3628,$3A28,$3E28
word = $22A8,$26A8,$2AA8,$2EA8,$32A8,$36A8,$3AA8,$3EA8
word = $2328,$2728,$2B28,$2F28,$3328,$3728,$3B28,$3F28
word = $23A8,$27A8,$2BA8,$2FA8,$33A8,$37A8,$3BA8,$3FA8
word = $2050,$2450,$2850,$2C50,$3050,$3450,$3850,$3C50
word = $20D0,$24D0,$28D0,$2CD0,$30D0,$34D0,$38D0,$3CD0
word = $2150,$2550,$2950,$2D50,$3150,$3550,$3950,$3D50
word = $21D0,$25D0,$29D0,$2DD0,$31D0,$35D0,$39D0,$3DD0
word = $2250,$2650,$2A50,$2E50,$3250,$3650,$3A50,$3E50
word = $22D0,$26D0,$2AD0,$2ED0,$32D0,$36D0,$3AD0,$3ED0
word = $2350,$2750,$2B50,$2F50,$3350,$3750,$3B50,$3F50
word = $23D0,$27D0,$2BD0,$2FD0,$33D0,$37D0,$3BD0,$3FD0
//
// Pixel masks for 7 contiguous pixels
//
word auxmask[] = $000F
word = $0070
word = $0000
word = $0300
word = $3C00
word = $4000
word = $0000
word memmask[] = $0000
word = $0001
word = $001E
word = $0060
word = $0000
word = $0700
word = $7800
//
// Solid colors
//
word auxclrs[] = $0000 // black
word = $2208 // magenta
word = $1144 // brown
word = $334C // orange
word = $0822 // dark green
word = $2A2A // gray 1
word = $1966 // green
word = $3B6E // yellow
word = $4411 // dark blue
word = $6619 // purple
word = $5555 // gray 2
word = $775D // pink
word = $4C33 // medium blue
word = $6E3B // light blue
word = $5D77 // aqua
word = $7F7F // white
word memclrs[] = $0000 // black
word = $4411 // magenta
word = $2208 // brown
word = $6619 // orange
word = $1144 // dark green
word = $5555 // gray 1
word = $334C // green
word = $775D // yellow
word = $0822 // dark blue
word = $4C33 // purple
word = $2A2A // gray 2
word = $6E3B // pink
word = $1966 // medium blue
word = $5D77 // light blue
word = $3B6E // aqua
word = $7F7F // white
word auxclr, memclr
//
// Modulo 7
//
byte mod7[] = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
byte = 0, 1, 2, 3, 4, 5, 6
//
// Divide 7
//
byte div7x2[] = 0, 0, 0, 0, 0, 0, 0
byte = 2, 2, 2, 2, 2, 2, 2
byte = 4, 4, 4, 4, 4, 4, 4
byte = 6, 6, 6, 6, 6, 6, 6
byte = 8, 8, 8, 8, 8, 8, 8
byte =10,10,10,10,10,10,10
byte =12,12,12,12,12,12,12
byte =14,14,14,14,14,14,14
byte =16,16,16,16,16,16,16
byte =18,18,18,18,18,18,18
byte =20,20,20,20,20,20,20
byte =22,22,22,22,22,22,22
byte =24,24,24,24,24,24,24
byte =26,26,26,26,26,26,26
byte =28,28,28,28,28,28,28
byte =30,30,30,30,30,30,30
byte =32,32,32,32,32,32,32
byte =34,34,34,34,34,34,34
byte =36,36,36,36,36,36,36
byte =38,38,38,38,38,38,38
def dhgrColor(c)#0
auxclr = auxclrs[c & $0F]
memclr = memclrs[c & $0F]
end
def dhgrPlot(x, y)#0
byte pix7
word pix7addr, mask
pix7addr = hgrscan[y] + div7x2[x]
pix7 = mod7[x]
mask = auxmask[pix7]
if mask
^page1x
*pix7addr = (*pix7addr & ~mask) | (mask & auxclr)
fin
mask = memmask[pix7]
if mask
^page1m
*pix7addr = (*pix7addr & ~mask) | (mask & memclr)
fin
end
def dhgrTile(x7, y8, tileptr)#0
word tileaddr
byte scan
tileaddr = hgrscan[y8 * 8] + x7 * 2
for scan = 0 to 7
^page1x
*tileaddr = *tileptr
tileptr = tileptr + 2
^page1m
*tileaddr = *tileptr
tileptr = tileptr + 2
tileaddr = tileaddr + $0400
next
end
def dhgrDst(x7, y, w7, h, dstptr)#0
word pix7addr
byte scan, b
for scan = y to y+h-1
pix7addr = hgrscan[scan] + x7 * 2
for b = 1 to w7
^page1x
*dstptr = *pix7addr
dstptr = dstptr + 2
^page1m
*dstptr = *pix7addr
dstptr = dstptr + 2
pix7addr = pix7addr + 2
next
next
end
def dhgrSrc(x7, y, w7, h, srcptr)#0
word pix7addr
byte scan, b
for scan = y to y+h-1
pix7addr = hgrscan[scan] + x7 * 2
for b = 1 to w7
^page1x
*pix7addr = *srcptr
srcptr = srcptr + 2
^page1m
*pix7addr = *srcptr
srcptr = srcptr + 2
pix7addr = pix7addr + 2
next
next
end
def dhgrMode(mode)
if mode == 0
^page1m
^showfull
^showhires
^showgraphics
^IOUdis = 0
^show80col = 0
^dhresena
^store80ena = 0
^page1m
memset($2000, 0, $2000)
^page1x
memset($2000, 0, $2000)
else
^store80dis = 0
^dhresdis
^show40col = 0
^showtext
^page1m
fin
return mode
end
def dhgrTest#0
byte i, j
word pixblk
setlineplot(@dhgrPlot)
for i = 0 to 191 step 4
dhgrColor(i)
line(0, 0, 139, i)
next
for i = 139 downto 0 step 4
dhgrColor(i)
line(0, 0, i, 191)
next
pixblk = heapalloc(16/2*20)
dhgrDst(0, 0, 2, 20, pixblk)
for i = 1 to 170
dhgrSrc(0, i, 2, 20, pixblk)
next
dhgrDst(0, 0, 1, 8, pixblk) // Create tile
for j = 0 to 19
for i = 0 to 19
dhgrTile(i, j, pixblk)
next
next
while ^$C000 < 128
loop
^$C010
end
dhgrmode(0)
dhgrtest
dhgrmode(-1)
done

View File

@ -60,6 +60,7 @@ DHCP = rel/DHCP\#FE1000
HTTPD = rel/HTTPD\#FE1000
TFTPD = rel/TFTPD\#FE1000
HGRLIB = rel/apple/HGRLIB\#FE1000
DHGRLIB = rel/apple/DHGRLIB\#FE1000
GRLIB = rel/apple/GRLIB\#FE1000
DGRLIB = rel/apple/DGRLIB\#FE1000
HGRSPRITE = rel/apple/HGRSPRITE\#FE1000
@ -114,7 +115,7 @@ TXTTYPE = .TXT
#SYSTYPE = \#FF2000
#TXTTYPE = \#040000
apple: $(PLVMZP_APL) $(PLASM) $(PLVM) $(PLVM01) $(PLVM02) $(PLVMJIT) $(PLVM802) $(PLVM03) $(PLVMJIT03) $(CMD) $(CMDJIT) $(JIT) $(JIT16) $(JITUNE) $(SOSCMD) $(SOSCMDJIT) $(PLASMAPLASM) $(CODEOPT) $(PLFORTH) $(HRFORTH) $(HR2FORTH) $(TX2FORTH) $(ZIPCHIP) $(MATCHFILES) $(ARGS) $(MEMMGR) $(MEMTEST) $(FIBER) $(FIBERTEST) $(LONGJMP) $(ED) $(MON) $(COPY) $(DEL) $(REN) $(CAT) $(NEWDIR) $(TYPE) $(SOS) $(ROD) $(SIEVE) $(PRIMEGAP) $(MOUSE) $(UTHERNET2) $(UTHERNET) $(ETHERIP) $(INET) $(DHCP) $(HTTPD) $(TFTPD) $(ROGUE) $(ROGUEMAP) $(ROGUECOMBAT) $(SFM) $(SFMSPRT) $(GRAFIX) $(GFXDEMO) $(LINES) $(HGRTILE) $(HGRFONT) $(HGRSPRITE) $(HGRLIB) $(TILETEST) $(HGRTEST) $(GRLIB) $(DGRLIB) $(GRTEST) $(DGRTEST) $(HGRTEST) $(FILEIO_APL) $(CONIO_APL) $(JOYBUZZ) $(PORTIO) $(SPIPORT) $(SDFAT) $(FATCAT) $(FATGET) $(FATPUT) $(FATWDSK) $(FATRDSK) $(INT32) $(INT32TEST) $(SANE) $(FPSTR) $(FPU) $(SANITY) $(LZ4) $(LZ4CAT) $(RPNCALC) $(SNDSEQ) $(PLAYSEQ) $(CONIOTEST)
apple: $(PLVMZP_APL) $(PLASM) $(PLVM) $(PLVM01) $(PLVM02) $(PLVMJIT) $(PLVM802) $(PLVM03) $(PLVMJIT03) $(CMD) $(CMDJIT) $(JIT) $(JIT16) $(JITUNE) $(SOSCMD) $(SOSCMDJIT) $(PLASMAPLASM) $(CODEOPT) $(PLFORTH) $(HRFORTH) $(HR2FORTH) $(TX2FORTH) $(ZIPCHIP) $(MATCHFILES) $(ARGS) $(MEMMGR) $(MEMTEST) $(FIBER) $(FIBERTEST) $(LONGJMP) $(ED) $(MON) $(COPY) $(DEL) $(REN) $(CAT) $(NEWDIR) $(TYPE) $(SOS) $(ROD) $(SIEVE) $(PRIMEGAP) $(MOUSE) $(UTHERNET2) $(UTHERNET) $(ETHERIP) $(INET) $(DHCP) $(HTTPD) $(TFTPD) $(ROGUE) $(ROGUEMAP) $(ROGUECOMBAT) $(SFM) $(SFMSPRT) $(GRAFIX) $(GFXDEMO) $(LINES) $(HGRTILE) $(HGRFONT) $(HGRSPRITE) $(HGRLIB) $(TILETEST) $(HGRTEST) $(DHGRLIB) $(GRLIB) $(DGRLIB) $(GRTEST) $(DGRTEST) $(HGRTEST) $(FILEIO_APL) $(CONIO_APL) $(JOYBUZZ) $(PORTIO) $(SPIPORT) $(SDFAT) $(FATCAT) $(FATGET) $(FATPUT) $(FATWDSK) $(FATRDSK) $(INT32) $(INT32TEST) $(SANE) $(FPSTR) $(FPU) $(SANITY) $(LZ4) $(LZ4CAT) $(RPNCALC) $(SNDSEQ) $(PLAYSEQ) $(CONIOTEST)
-rm vmsrc/plvmzp.inc
@ -191,7 +192,7 @@ $(PLVMZP_C64): FORCE
FORCE:
vmsrc/c64/cmd.a: vmsrc/c64/cmd.pla $(PLASM)
./$(PLASM) -AOW < vmsrc/c64/cmd.pla > vmsrc/c64/cmd.a
./$(PLASM) -AOW vmsrc/c64/cmd.pla
$(PLVMC64): vmsrc/c64/plvmc64.s vmsrc/c64/cmd.a
acme -f cbm -o $(PLVMC64) -l vmsrc/c64/plvmc64.sym vmsrc/c64/plvmc64.s
@ -465,6 +466,10 @@ $(HGRLIB): libsrc/apple/hgrlib.pla $(PLVM02) $(PLASM)
./$(PLASM) -AMOW libsrc/apple/hgrlib.pla
acme --setpc 4094 -o $(HGRLIB) libsrc/apple/hgrlib.a
$(DHGRLIB): libsrc/apple/dhgrlib.pla $(PLVM02) $(PLASM)
./$(PLASM) -AMOW libsrc/apple/dhgrlib.pla
acme --setpc 4094 -o $(DHGRLIB) libsrc/apple/dhgrlib.a
$(GRLIB): libsrc/apple/grlib.pla $(PLVM02) $(PLASM)
./$(PLASM) -AMOW libsrc/apple/grlib.pla
acme --setpc 4094 -o $(GRLIB) libsrc/apple/grlib.a

View File

@ -123,8 +123,12 @@ cp samplesrc/APPLE3.PIX#060000 prodos/demos/apple3/APPLE3.PIX.BIN
rm -rf prodos/bld
mkdir prodos/bld
cp rel/PLASM#FE1000 prodos/bld/PLASM.REL
cp rel/CODEOPT#FE1000 prodos/bld/CODEOPT.REL
cp rel/PLASM#FE1000 prodos/bld/PLASM.REL
cp rel/CODEOPT#FE1000 prodos/bld/CODEOPT.REL
cp ../sysfiles/EDASM#FF2000 prodos/bld/EDASM.SYS
cp ../sysfiles/EDASM.ASM#063000 prodos/bld/EDASM.ASM.BIN
cp ../sysfiles/EDASM.ED#063000 prodos/bld/EDASM.ED.BIN
cp ../sysfiles/EDASM.SWAP#062000 prodos/bld/EDASM.SWAP.BIN
mkdir prodos/bld/samples
cp samplesrc/hello.pla prodos/bld/samples/HELLO.PLA.TXT
@ -152,6 +156,11 @@ cp samplesrc/fppow.pla prodos/bld/samples/FPPOW.PLA.TXT
cp utilsrc/apple/mon.pla prodos/bld/samples/MON.PLA.TXT
cp utilsrc/apple/zipchip.pla prodos/bld/samples/ZIPCHIP.PLA.TXT
cp libsrc/apple/dhgrlib.pla prodos/bld/samples/DHGR.PLA.TXT
cp samplesrc/testrel.asm prodos/bld/samples/TESTREL.ASM.TXT
cp samplesrc/testext.asm prodos/bld/samples/TESTEXT.ASM.TXT
cp samplesrc/testasm.pla prodos/bld/samples/TESTASM.PLA.TXT
mkdir prodos/bld/scripts
cp scripts/rod.4th prodos/bld/scripts/ROD.4TH.TXT
cp scripts/bounce.4th prodos/bld/scripts/BOUNCE.4TH.TXT
@ -213,4 +222,6 @@ cp inc/spiport.plh prodos/bld/inc/SPIPORT.PLH.TXT
cp inc/testlib.plh prodos/bld/inc/TESTLIB.PLH.TXT
cp inc/grafix.plh prodos/bld/inc/GRAFIX.PLH.TXT
cp inc/lz4.plh prodos/bld/inc/LZ4.PLH.TXT
cp vmsrc/apple/plvmzp.inc prodos/bld/inc/PLVMZP.INC.TXT
cp inc/plasma.inc prodos/bld/inc/PLASMA.INC.TXT
cp inc/extheader.inc prodos/bld/inc/EXTHEADER.INC.TXT
cp inc/extdefseg.inc prodos/bld/inc/EXTDEFSEG.INC.TXT

View File

@ -1,3 +1,6 @@
include "inc/cmdsys.plh"
puts("a"); putln
puts("bb"); putln
puts("ccc"); putln
puts("Hello, world.\n")
done

View File

@ -71,8 +71,6 @@ def nums(range)#0
array[1]++
array[0] = array[0] + 1
array++
a1[0]++
a1++
puti(array[0]);putln
puti(array[1]);putln
end

View File

@ -0,0 +1,7 @@
import test
predef hello#0
predef goodbye#0
end
goodbye
done

61
src/samplesrc/testext.asm Normal file
View File

@ -0,0 +1,61 @@
;
; EXTENDED REL MODULE WITH DEPENDENCIES, BYTECODE SEGMENT, AND INIT
;
INCLUDE INC/PLASMA.INC
;
; EXT REL HEADER
;
RESFLAGS EQU 0
INCLUDE INC/EXTHEADER.INC
;
; ADD MODULE DEPENDENCIES
; (DCI BACKWARDS HI/LO BIT FROM REL FILE)
;
MSB ON
ASC "CMDSY"
MSB OFF
ASC "S"
;
; EXTERNALS USED FROM CMDSYS
;
EXTRN PUTS
EXTRN PUTLN
;
; TERMINATE DEPENDENCY LIST WITH ZERO
;
DB 0
;
; DATA AND 6502 CODE SEGMENT
;
HIMSG STR "Hello"
HELLO DEF HELLO ; CALLABLE FROM EXTERNAL MODULES
LDA #>HIMSG
LDY #<HIMSG
DEX
STA ESTKL,X
STY ESTKH,X
JSR PUTS
JMP PUTLN
BYEMSG STR "Goodbye"
GOODBYE DEF GOODBYE ; CALLABLE FROM EXTERNAL MODULES
LDA #>BYEMSG
LDY #<BYEMSG
DEX
STA ESTKL,X
STY ESTKH,X
JSR PUTS
JMP PUTLN
;
; INITIALIZE MODULE AND RETURN MOD KEEP STATUS
;
INIT JSR HELLO
LDA #>MODKEEP
LDY #<MODKEEP
DEX
STA ESTKL,X
STY ESTKH,X
RTS
;
; EXT REL DEFSEG
;
INCLUDE INC/EXTDEFSEG.INC

30
src/samplesrc/testrel.asm Normal file
View File

@ -0,0 +1,30 @@
;
; SIMPLE REL FILE - NO DEPENDENCIES, NO INIT CODE
;
INCLUDE INC/PLASMA.INC
;
; EXTERNALS USED BY THIS MODULE
;
EXTRN PUTS
EXTRN PUTLN
;
; DATA AND MACHINE CODE FOR THIS REL MODULE
;
HIMSG STR "Hello"
HELLO DEF HELLO
LDA #>HIMSG
LDY #<HIMSG
DEX
STA ESTKL,X
STY ESTKH,X
JSR PUTS
JMP PUTLN
BYEMSG STR "Goodbye"
GOODBYE DEF GOODBYE
LDA #>BYEMSG
LDY #<BYEMSG
DEX
STA ESTKL,X
STY ESTKH,X
JSR PUTS
JMP PUTLN

View File

@ -205,7 +205,7 @@ def emit_caseblock(cnt, oflist, typlist, taglist)#0
emit_pending_seq
emit_byte(cnt)
for i = 0 to cnt-1
if typlist=>[i] & CONSTADDR_TYPE
if typlist=>[i] == CONSTADDR_TYPE
emit_addr(oflist=>[i], 0)
else
emit_word(oflist=>[i])

View File

@ -614,7 +614,7 @@ def parse_stmnt
byte type, elem_type, elem_size, cfnvals
word seq, fromseq, toseq, tag_prevbrk, tag_prevcnt, tag_else, tag_endif, tag_while, tag_wend
word tag_repeat, tag_for, tag_choice, tag_of, idptr, addr, stepdir
word caseconst, casetype, casecnt, caseval, casetyp, casetag, i
word case_const, case_type, casecnt, caseval, casetyp, casetag, i
if token <> END_TKN and token <> DONE_TKN and token <> OF_TKN and token <> DEFAULT_TKN
prevstmnt = token
@ -802,9 +802,9 @@ def parse_stmnt
tag_prevbrk = break_tag
break_tag = new_tag(RELATIVE_FIXUP)
tag_choice = new_tag(RELATIVE_FIXUP)
caseval = heapalloc(CASENUM)
casetyp = heapalloc(CASENUM)
casetag = heapalloc(CASENUM)
caseval = heapalloc(CASENUM*2)
casetyp = heapalloc(CASENUM*2)
casetag = heapalloc(CASENUM*2)
casecnt = 0
seq, cfnvals = parse_expr(NULL)
if !seq; exit_err(ERR_INVAL|ERR_STATE); fin
@ -819,10 +819,10 @@ def parse_stmnt
when token
is OF_TKN
if casecnt == CASENUM; exit_err(ERR_OVER|ERR_TABLE); fin
caseconst, drop, casetype = parse_constexpr
tag_of = new_tag(RELATIVE_FIXUP)
i = casecnt
while i > 0 and caseval=>[i-1] > caseconst
case_const, drop, case_type = parse_constexpr
tag_of = new_tag(RELATIVE_FIXUP)
i = casecnt
while i > 0 and caseval=>[i-1] > case_const
//
// Move larger case consts up
//
@ -831,9 +831,9 @@ def parse_stmnt
casetag=>[i] = casetag=>[i-1]
i--
loop
if i < casecnt and caseval=>[i] == caseconst; exit_err(ERR_DUP|ERR_STATE); fin
caseval=>[i] = caseconst
casetyp=>[i] = casetype
if i < casecnt and caseval=>[i] == case_const; exit_err(ERR_DUP|ERR_STATE); fin
caseval=>[i] = case_const
casetyp=>[i] = case_type
casetag=>[i] = tag_of
casecnt++
emit_tag(tag_of)
@ -848,7 +848,7 @@ def parse_stmnt
emit_branch(tag_of)
fin
emit_tag(tag_choice)
emit_caseblock(casecnt, caseval, casetype, casetag)
emit_caseblock(casecnt, caseval, casetyp, casetag)
tag_choice = 0
if tag_of
emit_tag(tag_of)

View File

@ -508,7 +508,7 @@ include "toolsrc/parse.pla"
//
// Look at command line arguments and compile module
//
puts("PLASMA Compiler, Version 2.1\n")
puts("PLASMA Compiler, Version 2.11\n")
arg = argNext(argFirst)
if ^arg and ^(arg + 1) == '-'
opt = arg + 2

View File

@ -1,5 +1,5 @@
const RELADDR = $1000
const inbuff = $200
const inbuff = $01FF
const freemem = $0006
//
// System flags: memory allocator screen holes.
@ -40,7 +40,7 @@ predef sext(a)#1, divmod(a,b)#2, execmod(modfile)#1, syslookuptbl(a)#1
//
// Exported CMDSYS table
//
word version = $0210 // 02.10
word version = $0211 // 02.11
word syspath
word syscmdln
word = @execmod
@ -53,7 +53,7 @@ word = @syslookuptbl
// String pool.
//
byte autorun[] = "AUTORUN"
byte verstr[] = "\nPLASMA BETA"
byte verstr[] = "\nAPPLE1 PLASMA "
byte freestr[] = "MEM FREE:$"
byte errorstr[] = "ERR:$"
byte prompt[] = "PLASMA"
@ -132,24 +132,17 @@ word syslibsym = @exports
//
// Utility functions
//
asm saveX#0
STX XREG+1
end
asm restoreX#0
XREG LDX #$00
RTS
end
//
// CALL CFFA1 API ENTRYPOINT
// SYSCALL(CMD, 0)
//
asm syscall(cmd, null)#1
INX
LDA ESTKL,X
STX ESP
TAX
JSR $900C
LDX ESP
INX
LDY #$00
STA ESTKL,X
STY ESTKH,X
@ -199,7 +192,7 @@ end
// QUIT TO MONITOR
//
asm quit()#0
JMP $9000
JMP $9000
end
//
// SET MEMORY TO VALUE
@ -666,25 +659,42 @@ asm reloc(modfix, modofst, bytecode, rld)#3
LDY #$00
- LDA (SRC),Y
BEQ RLDEX ; END OF RLD
PHA
INY
LDA (SRC),Y
INY
CLC
ADC ESTKL+3,X ; ADDR=ENTRY=>1+MODFIX
STA DSTL
INY
LDA (SRC),Y
ADC ESTKH+3,X
STA DSTH
PLA
LDY #$00
LDA (SRC),Y
AND #$10 ; EXTERN REF - EXIT
BNE RLDEX
TAY ; FIXUP=*ADDR+MODOFST
LDA (SRC),Y
BMI FIX16
AND #$40
BNE FIXMSB
FIXLSB LDA (DST),Y
CLC
ADC ESTKL+2,X
CLC
BCC FIX8
FIXMSB LDY #$03
LDA (SRC),Y ; FIXUPH=(ENTRY->3+MODOFSTL)+(^ADDR+MODOFSTH)
CLC
ADC ESTKL+2,X
LDY #$00
LDA (DST),Y
INY
ADC ESTKH+2,X
CLC
BCC FIX8
FIX16 LDA (DST),Y ; FIXUP=*ADDR+MODOFST
CLC
ADC ESTKL+2,X
STA TMPL
INY
LDA (DST),Y
ADC ESTKH+2,X
CMP ESTKH+1,X ; FIXUP >= BYTECODE?
@ -698,7 +708,7 @@ asm reloc(modfix, modofst, bytecode, rld)#3
+ STA (DST),Y ; *ADDR=FIXUP
DEY
LDA TMPL
STA (DST),Y
FIX8 STA (DST),Y
LDA SRCL ; NEXT ENTRY
; CLC
ADC #$04
@ -727,23 +737,24 @@ end
asm cout(c)#0
LDA ESTKL,X
JSR TOUPR
INX
ORA #$80
JMP $FFEF
; JMP $FDED
end
asm cin()#1
DEX
- LDA $D011
;- LDA $C000
BPL -
LDA $D010
; STA $C010
AND #$7F
DEX
STA ESTKL,X
LDA #$00
STA ESTKH,X
RTS
end
def syslookuptbl(dci)#1
return lookuptbl(dci, symtbl)
end
def crout()#0
cout($0D)
end
@ -761,32 +772,35 @@ end
def rdstr(prompt)#1
byte ch, maxlen
maxlen = 0
inbuff.0 = 0
^inbuff = 0
cout(prompt)
repeat
ch = cin
when ch
is $15 // right arrow
if ^inbuff < maxlen //inbuff.0 < maxlen
inbuff.0++
ch = inbuff[inbuff.0]
if ^inbuff < maxlen
^inbuff++
ch = ^(inbuff + ^inbuff)]
cout(ch)
fin
break
is $08 // left arrow
if inbuff.0
if ^inbuff
cout('\\')
cout(inbuff[inbuff.0])
cout(^(inbuff + ^inbuff))
cout($08); cout($08); cout($08) // backspace if supported
prstr(" ")
cout($08); cout($08); cout($08)
inbuff.0--
fin
break
is $04 // ctrl-d
if inbuff.0
cout('#')
cout(inbuff[inbuff.0])
memcpy(inbuff + inbuff.0, inbuff + inbuff.0 + 1, maxlen - inbuff.0)
cout(^(inbuff + ^inbuff))
memcpy(inbuff + ^inbuff, inbuff + ^inbuff + 1, maxlen - ^inbuff)
maxlen--
inbuff.0--
^inbuff--
fin
break
is $0C // ctrl-l
@ -794,25 +808,26 @@ def rdstr(prompt)#1
prstr(inbuff)
break
is $0D // return
break
is $18 // ctrl-x
crout
inbuff.0 = 0
^inbuff = 0
break
is $9B // escape
inbuff.0 = 0
^inbuff = 0
ch = $0D
break
otherwise
if ch >= ' '
cout(ch)
inbuff.0++
inbuff[inbuff.0] = ch
if inbuff.0 > maxlen
maxlen = inbuff.0
^inbuff++
^(inbuff + ^inbuff) = ch
if ^inbuff > maxlen
maxlen = ^inbuff
fin
fin
wend
until ch == $0D or inbuff.0 == $7F
until ch == $0D or ^inbuff == $7F
cout($0D)
return inbuff
end
@ -841,14 +856,6 @@ end
// CFFA1 routines
// FILE I/O
//
//def opendir
// perr = syscall($10, 0)
// return perr
//end
//def readdir
// perr = syscall($12, 0)
// return *CFFAEntryPtr
//end
def finddirentry(filename)#1
*CFFAFileName = filename
perr = syscall($14, 0)
@ -899,6 +906,9 @@ end
//
// Symbol table routines.
//
def syslookuptbl(dci)#1
return lookuptbl(dci, symtbl)
end
def addsym(sym, addr)#0
while ^sym & $80
^lastsym = ^sym
@ -965,7 +975,7 @@ def loadmod(mod)#1
moddep = @header.1
defofst = modsize + RELADDR
init = 0
if rdlen > 4 and heap=>2 == $6502 // magic number
if rdlen > 4 and header:2 == $6502 // magic number
//
// This is an EXTended RELocatable (data+bytecode) module.
//
@ -1038,34 +1048,9 @@ def loadmod(mod)#1
while ^rld
rld, addr, fixup = reloc(modfix, modofst, bytecode, rld)
if ^rld
*addr = ^rld & $10 ?? *addr + lookupextern(esd, rld->3) :: lookupdef(fixup + defofst, deftbl)
*addr = ^rld & $10 ?? *addr + lookupextern(esd, rld->3) :: lookupdef(fixup, deftbl)
rld = rld + 4
fin
//addr = rld=>1 + modfix
//if uword_isge(addr, modaddr) // Skip fixups to header
// if type & $80 // WORD sized fixup.
// fixup = *addr
// else // BYTE sized fixup.
// fixup = ^addr
// fin
// if ^rld & $10 // EXTERN reference.
// fixup = fixup + lookupextern(esd, rld->3)
// else // INTERN fixup.
// fixup = fixup + modofst
// if uword_isge(fixup, bytecode)
// //
// // Bytecode address - replace with call def directory.
// //
// fixup = lookupdef(fixup + defofst, deftbl)
// fin
// fin
// if type & $80 // WORD sized fixup.
// *addr = fixup
// else // BYTE sized fixup.
// ^addr = fixup
// fin
//fin
//rld = rld + 4
loop
//
// Run through the External/Entry Symbol Directory.
@ -1082,7 +1067,7 @@ def loadmod(mod)#1
//
// Use the def directory address for bytecode.
//
addr = lookupdef(addr + defofst, deftbl)
addr = lookupdef(addr, deftbl)
fin
addsym(sym, addr)
fin
@ -1099,9 +1084,9 @@ def loadmod(mod)#1
//
// Call init routine if it exists.
//
fixup = 0
fixup = modkeep
if init
init = init - defofst + bytecode
init = init + defofst
fixup = adddef(init, @deflast)()
if fixup < 0
perr = -fixup
@ -1217,6 +1202,7 @@ while 1
when toupper(parsecmd(cmdptr))
is 'Q'
quit
break
is 'M'
syscall($02, 0)
break
@ -1233,7 +1219,7 @@ while 1
else
prstr(@okstr)
fin
crout()
crout()
fin
prstr(@prompt)
cmdptr = rdstr($BA)

View File

@ -39,7 +39,7 @@ predef lookuptbl(dci)#1, execsys(sysfile)#0
//
// Exported CMDSYS table
//
word version = $0210 // 02.01 Dev
word version = $0211 // 02.11
word syspath
word syscmdln
word = @execmod, @open, @close, @read, 0
@ -753,25 +753,42 @@ asm reloc(modfix, modofst, bytecode, rld)#3
LDY #$00
- LDA (SRC),Y
BEQ RLDEX ; END OF RLD
PHA
INY
LDA (SRC),Y
INY
CLC
ADC ESTKL+3,X ; ADDR=ENTRY=>1+MODFIX
STA DSTL
INY
LDA (SRC),Y
ADC ESTKH+3,X
STA DSTH
PLA
LDY #$00
LDA (SRC),Y
AND #$10 ; EXTERN REF - EXIT
BNE RLDEX
TAY ; FIXUP=*ADDR+MODOFST
LDA (SRC),Y
BMI FIX16
AND #$40
BNE FIXMSB
FIXLSB LDA (DST),Y
CLC
ADC ESTKL+2,X
CLC
BCC FIX8
FIXMSB LDY #$03
LDA (SRC),Y ; FIXUPH=(ENTRY->3+MODOFSTL)+(^ADDR+MODOFSTH)
CLC
ADC ESTKL+2,X
LDY #$00
LDA (DST),Y
INY
ADC ESTKH+2,X
CLC
BCC FIX8
FIX16 LDA (DST),Y ; FIXUP=*ADDR+MODOFST
CLC
ADC ESTKL+2,X
STA TMPL
INY
LDA (DST),Y
ADC ESTKH+2,X
CMP ESTKH+1,X ; FIXUP >= BYTECODE?
@ -785,7 +802,7 @@ asm reloc(modfix, modofst, bytecode, rld)#3
+ STA (DST),Y ; *ADDR=FIXUP
DEY
LDA TMPL
STA (DST),Y
FIX8 STA (DST),Y
LDA SRCL ; NEXT ENTRY
; CLC
ADC #$04
@ -962,7 +979,7 @@ def adddef(addr, deflast)#1
return defentry
end
def loadmod(mod)#1
word rdlen, modsize, bytecode, codefix, defofst, defcnt, init, initcode[], fixup
word rdlen, modsize, bytecode, defofst, defcnt, init, initcode[], fixup
word addr, defaddr, modaddr, modfix, modofst, modend
word deftbl, deflast
word moddep, rld, esd, sym
@ -1057,15 +1074,13 @@ def loadmod(mod)#1
modofst = modfix - RELADDR
modend = modaddr + modsize
bytecode = defofst + modofst
defofst = bytecode - defofst
rld = modend // Re-Locatable Directory
esd = rld // Extern+Entry Symbol Directory
while ^esd // Scan to end of ESD
esd = esd + 4
loop
esd = esd + 1
defaddr = bytecode
codefix = defaddr - bytecode
defofst = defaddr - defofst
//
// Run through the DeFinition Dictionary.
//
@ -1082,7 +1097,7 @@ def loadmod(mod)#1
while ^rld
rld, addr, fixup = reloc(modfix, modofst, bytecode, rld)
if ^rld
*addr = ^rld & $10 ?? *addr + lookupextern(esd, rld->3) :: lookupdef(fixup + codefix, deftbl)
*addr = ^rld & $10 ?? *addr + lookupextern(esd, rld->3) :: lookupdef(fixup, deftbl)
rld = rld + 4
fin
loop
@ -1101,7 +1116,7 @@ def loadmod(mod)#1
//
// Use the def directory address for bytecode.
//
addr = lookupdef(addr + codefix, deftbl)
addr = lookupdef(addr, deftbl)
fin
addsym(sym, addr)
fin
@ -1120,7 +1135,7 @@ def loadmod(mod)#1
//
// Call init routine if it exists.
//
initcode = 0
initcode = modkeep
if init
init = init + defofst
initcode = adddef(init, @deflast)()
@ -1352,7 +1367,7 @@ def docmds#0
if perr
prstr("ERR:$")
prbyte(perr)
crout()
crout()
fin
fin
prstr(pfxop(prefix, GET_PFX))
@ -1371,7 +1386,7 @@ heap = @lastdef
//
// Print PLASMA version
//
prstr("PLASMA 2.1 64K\n")//; prbyte(version.1); cout('.'); prbyte(version.0); crout
prstr("PLASMA 2.11 64K\n")
//
// Init symbol table.
//

View File

@ -53,11 +53,10 @@ predef memset(addr,value,size)#0, memcpy(dst,src,size)#0, strcpy(dst,src)#1, str
predef uword_isgt(a,b)#1, uword_isge(a,b)#1, uword_islt(a,b)#1, uword_isle(a,b)#1, sext(a)#1, divmod(a,b)#2
predef execmod(modfile)#1, open(path)#1, close(refnum)#1, read(refnum, buf, len)#1
predef lookuptbl(dci)#1, execsys(sysfile)#0
//
// Exported CMDSYS table
//
word version = $0210 // 02.10
word version = $0211 // 02.11
word syspath
word syscmdln
word = @execmod, @open, @close, @read, 0
@ -773,25 +772,42 @@ asm reloc(modfix, modofst, bytecode, rld)#3
LDY #$00
- LDA (SRC),Y
BEQ RLDEX ; END OF RLD
PHA
INY
LDA (SRC),Y
INY
CLC
ADC ESTKL+3,X ; ADDR=ENTRY=>1+MODFIX
STA DSTL
INY
LDA (SRC),Y
ADC ESTKH+3,X
STA DSTH
PLA
LDY #$00
LDA (SRC),Y
AND #$10 ; EXTERN REF - EXIT
BNE RLDEX
TAY ; FIXUP=*ADDR+MODOFST
LDA (SRC),Y
BMI FIX16
AND #$40
BNE FIXMSB
FIXLSB LDA (DST),Y
CLC
ADC ESTKL+2,X
CLC
BCC FIX8
FIXMSB LDY #$03
LDA (SRC),Y ; FIXUPH=(ENTRY->3+MODOFSTL)+(^ADDR+MODOFSTH)
CLC
ADC ESTKL+2,X
LDY #$00
LDA (DST),Y
INY
ADC ESTKH+2,X
CLC
BCC FIX8
FIX16 LDA (DST),Y ; FIXUP=*ADDR+MODOFST
CLC
ADC ESTKL+2,X
STA TMPL
INY
LDA (DST),Y
ADC ESTKH+2,X
CMP ESTKH+1,X ; FIXUP >= BYTECODE?
@ -805,7 +821,7 @@ asm reloc(modfix, modofst, bytecode, rld)#3
+ STA (DST),Y ; *ADDR=FIXUP
DEY
LDA TMPL
STA (DST),Y
FIX8 STA (DST),Y
LDA SRCL ; NEXT ENTRY
; CLC
ADC #$04
@ -930,26 +946,26 @@ def allocxheap(size)#1
word xaddr
xaddr = xheap
xheap = xheap + size
if systemflags & restxt1
if uword_isle(xaddr, $0800) and uword_isgt(xheap, $0400)
if systemflags & resxtxt1
if uword_islt(xaddr, $0800) and uword_isgt(xheap, $0400)
xaddr = $0800
xheap = xaddr + size
fin
fin
if systemflags & restxt2
if uword_isle(xaddr, $0C00) and uword_isgt(xheap, $0800)
if systemflags & resxtxt2
if uword_islt(xaddr, $0C00) and uword_isgt(xheap, $0800)
xaddr = $0C00
xheap = xaddr + size
fin
fin
if systemflags & resxhgr1
if uword_isle(xaddr, $4000) and uword_isgt(xheap, $2000)
if uword_islt(xaddr, $4000) and uword_isgt(xheap, $2000)
xaddr = $4000
xheap = xaddr + size
fin
fin
if systemflags & resxhgr2
if uword_isle(xaddr, $6000) and uword_isgt(xheap, $4000)
if uword_islt(xaddr, $6000) and uword_isgt(xheap, $4000)
xaddr = $6000
xheap = xaddr + size
fin
@ -1196,7 +1212,7 @@ def loadmod(mod)#1
//
// Call init routine if it exists.
//
initcode = 0
initcode = modkeep
if init
init = init + defofst
initcode = adddef(deffirst, init, @deflast)()
@ -1437,7 +1453,7 @@ def docmds#0
if perr
prstr("ERR:$")
prbyte(perr)
crout()
crout()
fin
fin
prstr(pfxop(prefix, GET_PFX))
@ -1456,7 +1472,7 @@ heap = @lastdef
//
// Print PLASMA version
//
prstr("PLASMA 2.1 128K\n")//; prbyte(version.1); cout('.'); prbyte(version.0); crout
prstr("PLASMA 2.11 128K\n")
//
// Init symbol table.
//

View File

@ -22,6 +22,7 @@ OPPAGE = OPIDX+1
;* INTERPRETER HEADER+INITIALIZATION
;*
*= $0280
;* *= $2000
SEGBEGIN JMP VMINIT
;*
;* SYSTEM INTERPRETER ENTRYPOINT
@ -33,7 +34,7 @@ INTERP PLA
PLA
ADC #$00
STA IPH
LDY #$01
LDY #$00
JMP FETCHOP
;*
;* ENTER INTO USER BYTECODE INTERPRETER
@ -774,7 +775,7 @@ ISGE LDA ESTKL+1,X
BPL ISTRU
BMI ISFLS
+
- BPL ISFLS
- BPL ISFLS
BMI ISTRU
ISLE LDA ESTKL,X
CMP ESTKL+1,X
@ -1097,7 +1098,9 @@ JUMP INY
JMP FETCHOP
A1CMD !SOURCE "vmsrc/apple/a1cmd.a"
SEGEND = *
VMINIT LDY #$10 ; INSTALL PAGE 0 FETCHOP ROUTINE
VMINIT LDX #$FE ; INIT STACK LEAVING ROOM FOR INBUFF SIZE
TXS
LDY #$10 ; INSTALL PAGE 0 FETCHOP ROUTINE
- LDA PAGE0-1,Y
STA DROP-1,Y
DEY

View File

@ -45,12 +45,12 @@ predef syslookuptbl(dci)#1
//
// Exported CMDSYS table
//
word version = $0210 // 02.10
word version = $0211 // 02.11
word syspath
word cmdlnptr
word = @execmod, @open, @close, @read, @write
byte perr
byte jitcount = 0 // Keep these here for compatibility
byte jitcount = 0
byte jitsize = 0
byte refcons = 0
byte devcons = 0
@ -731,25 +731,42 @@ asm reloc(modfix, modofst, bytecode, rld)#3
LDY #$00
- LDA (SRC),Y
BEQ RLDEX ; END OF RLD
PHA
INY
LDA (SRC),Y
INY
CLC
ADC ESTKL+3,X ; ADDR=ENTRY=>1+MODFIX
STA DSTL
INY
LDA (SRC),Y
ADC ESTKH+3,X
STA DSTH
PLA
LDY #$00
LDA (SRC),Y
AND #$10 ; EXTERN REF - EXIT
BNE RLDEX
TAY ; FIXUP=*ADDR+MODOFST
LDA (SRC),Y
BMI FIX16
AND #$40
BNE FIXMSB
FIXLSB LDA (DST),Y
CLC
ADC ESTKL+2,X
CLC
BCC FIX8
FIXMSB LDY #$03
LDA (SRC),Y ; FIXUPH=(ENTRY->3+MODOFSTL)+(^ADDR+MODOFSTH)
CLC
ADC ESTKL+2,X
LDY #$00
LDA (DST),Y
INY
ADC ESTKH+2,X
CLC
BCC FIX8
FIX16 LDA (DST),Y ; FIXUP=*ADDR+MODOFST
CLC
ADC ESTKL+2,X
STA TMPL
INY
LDA (DST),Y
ADC ESTKH+2,X
CMP ESTKH+1,X ; FIXUP >= BYTECODE?
@ -763,7 +780,7 @@ asm reloc(modfix, modofst, bytecode, rld)#3
+ STA (DST),Y ; *ADDR=FIXUP
DEY
LDA TMPL
STA (DST),Y
FIX8 STA (DST),Y
LDA SRCL ; NEXT ENTRY
; CLC
ADC #$04
@ -1214,7 +1231,7 @@ def loadmod(mod)#1
//
// Call init routine if it exists.
//
initcode = 0
initcode = modkeep
if init
initcode = adddef(defext, init + defofst, @deflast)()
if initcode < 0
@ -1267,7 +1284,7 @@ cmdlnptr = @cmdln
// Print PLASMA version
//
init_cons
prstr("PLASMA 2.1\n")//; putb(version.1); putc('.'); putb(version.0); putln
prstr("PLASMA 2.11\n")
prstr("MEM:$"); prword(availheap); crout
//
// Exec command line parser

View File

@ -56,7 +56,7 @@ predef syslookuptbl(dci)#1
//
// Exported CMDSYS table
//
word version = $0210 // 02.10
word version = $0211 // 02.11
word syspath
word cmdlnptr
word = @execmod, @open, @close, @read, @write
@ -742,25 +742,42 @@ asm reloc(modfix, modofst, bytecode, rld)#3
LDY #$00
- LDA (SRC),Y
BEQ RLDEX ; END OF RLD
PHA
INY
LDA (SRC),Y
INY
CLC
ADC ESTKL+3,X ; ADDR=ENTRY=>1+MODFIX
STA DSTL
INY
LDA (SRC),Y
ADC ESTKH+3,X
STA DSTH
PLA
LDY #$00
LDA (SRC),Y
AND #$10 ; EXTERN REF - EXIT
BNE RLDEX
TAY ; FIXUP=*ADDR+MODOFST
LDA (SRC),Y
BMI FIX16
AND #$40
BNE FIXMSB
FIXLSB LDA (DST),Y
CLC
ADC ESTKL+2,X
CLC
BCC FIX8
FIXMSB LDY #$03
LDA (SRC),Y ; FIXUPH=(ENTRY->3+MODOFSTL)+(^ADDR+MODOFSTH)
CLC
ADC ESTKL+2,X
LDY #$00
LDA (DST),Y
INY
ADC ESTKH+2,X
CLC
BCC FIX8
FIX16 LDA (DST),Y ; FIXUP=*ADDR+MODOFST
CLC
ADC ESTKL+2,X
STA TMPL
INY
LDA (DST),Y
ADC ESTKH+2,X
CMP ESTKH+1,X ; FIXUP >= BYTECODE?
@ -774,7 +791,7 @@ asm reloc(modfix, modofst, bytecode, rld)#3
+ STA (DST),Y ; *ADDR=FIXUP
DEY
LDA TMPL
STA (DST),Y
FIX8 STA (DST),Y
LDA SRCL ; NEXT ENTRY
; CLC
ADC #$04
@ -1237,7 +1254,7 @@ def loadmod(mod)#1
//
// Call init routine if it exists.
//
initcode = 0
initcode = modkeep
if init
initcode = adddef(deffirst, defext, init + defofst, @deflast)()
if initcode < 0
@ -1290,7 +1307,7 @@ cmdlnptr = @cmdln
// Print PLASMA version
//
init_cons
prstr("PLASMA 2.1 JITC\n")//; putb(version.1); putc('.'); putb(version.0); putln
prstr("PLASMA 2.11 JITC\n")
prstr("MEM:$"); prword(availheap); crout
//
// Exec command line parser

View File

@ -26,17 +26,19 @@ predef cin()#1, rdstr(p)#1, toupper(c)#1, strcpy(dst,src)#1, strcat(dst,src)#1
predef markheap()#1, allocheap(size)#1, allocalignheap(size, pow2, freeaddr), releaseheap(newheap)#1, availheap()#1
predef memset(addr,value,size)#0, memcpy(dst,src,size)#0
predef uword_isgt(a,b)#1, uword_isge(a,b)#1, uword_islt(a,b)#1, uword_isle(a,b)#1
predef sext(a)#1, divmod(a,b)#2, execmod(modfile)#1
predef sext(a)#1, divmod(a,b)#2, execmod(modfile)#1, syslookuptbl(dci)#1
//
// Exported CMDSYS table
//
word version = $0200 // 02.00
word version = $0211 // 02.11
word syspath
word syscmdln
word = @execmod, 0, 0, 0, 0
byte perr
byte jitcount = 0
byte jitsize = 0
word = 0
word = @syslookuptbl
//
// String pool.
//
@ -651,25 +653,42 @@ asm reloc(modfix, modofst, bytecode, rld)#3
LDY #$00
- LDA (SRC),Y
BEQ RLDEX ; END OF RLD
PHA
INY
LDA (SRC),Y
INY
CLC
ADC ESTKL+3,X ; ADDR=ENTRY=>1+MODFIX
STA DSTL
INY
LDA (SRC),Y
ADC ESTKH+3,X
STA DSTH
PLA
LDY #$00
LDA (SRC),Y
AND #$10 ; EXTERN REF - EXIT
BNE RLDEX
TAY ; FIXUP=*ADDR+MODOFST
LDA (SRC),Y
BMI FIX16
AND #$40
BNE FIXMSB
FIXLSB LDA (DST),Y
CLC
ADC ESTKL+2,X
CLC
BCC FIX8
FIXMSB LDY #$03
LDA (SRC),Y ; FIXUPH=(ENTRY->3+MODOFSTL)+(^ADDR+MODOFSTH)
CLC
ADC ESTKL+2,X
LDY #$00
LDA (DST),Y
INY
ADC ESTKH+2,X
CLC
BCC FIX8
FIX16 LDA (DST),Y ; FIXUP=*ADDR+MODOFST
CLC
ADC ESTKL+2,X
STA TMPL
INY
LDA (DST),Y
ADC ESTKH+2,X
CMP ESTKH+1,X ; FIXUP >= BYTECODE?
@ -683,7 +702,7 @@ asm reloc(modfix, modofst, bytecode, rld)#3
+ STA (DST),Y ; *ADDR=FIXUP
DEY
LDA TMPL
STA (DST),Y
FIX8 STA (DST),Y
LDA SRCL ; NEXT ENTRY
; CLC
ADC #$04
@ -823,6 +842,9 @@ end
//
// Symbol table routines.
//
def syslookuptbl(dci)#1
return lookuptbl(dci, symtbl)
end
def addsym(sym, addr)#0
while ^sym & $80
^lastsym = ^sym
@ -998,7 +1020,7 @@ def loadmod(mod)#1
//
// Call init routine if it exists.
//
fixup = 0
fixup = modkeep
if init
init = init - defofst + bytecode
fixup = adddef(init, @deflast)()
@ -1078,7 +1100,7 @@ heap = *freemem
//
// Print PLASMA version
//
prstr("\nPLASMA 2.0 Dev\n") //; prbyte(version.1); cout('.'); prbyte(version.0); crout
prstr("\nPLASMA 2.11\n")
//
// Init symbol table.
//

View File

@ -121,8 +121,8 @@ OPTBL !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 00 02
!WORD NEG,COMP,BAND,IOR,XOR,SHL,SHR,IDXW ; 90 92 94 96 98 9A 9C 9E
!WORD BRGT,BRLT,INCBRLE,ADDBRLE,DECBRGE,SUBBRGE,BRAND,BROR ; A0 A2 A4 A6 A8 AA AC AE
!WORD ADDLB,ADDLW,ADDAB,ADDAW,IDXLB,IDXLW,IDXAB,IDXAW ; B0 B2 B4 B6 B8 BA BC BE
!WORD NATV ; C0
;*
!WORD NATV,JUMPZ,JUMP ; C0 C2 C4
;;*
;* DIV TOS-1 BY TOS
;*
DIV JSR _DIV
@ -1193,6 +1193,28 @@ NATV TYA ; FLATTEN IP
JMP (IP)
+ INC IPH
JMP (IP)
;*
;* JUMPS FOR FORTH COMPILER
;*
JUMPZ INX
LDA ESTKH-1,X
ORA ESTKL-1,X
BEQ JUMP
INY ;+INC_IP
INY
BMI +
JMP NEXTOP
+ JMP FIXNEXT
JUMP INY
LDA (IP),Y
PHA
INY
LDA (IP),Y
STA IPH
PLA
STA IPL
LDY #$00
JMP FETCHOP
CMD !SOURCE "vmsrc/c64/cmd.a"
SEGEND = *
VMINIT JSR $FFE7 ; CLOSE ALL CHANNELS