Page 1 of 1

v6502 mini-assembler in Apple-1 emulator

Posted: 27 Jan 2020, 23:26
by marcelk
For those interested in software developments, our Apple-1 emulation now includes not just the Baum/Wozniak disassembler as published in DrDobbs, but also their famous mini-assembler back ported from Apple ][. With this you can enter MOS 6502 mnemonics on the Gigatron itself and execute them without having to remember the opcodes.

Usage:

Code: Select all

D13R                    Enter mini-assembler (provisional)
                        Prompt is now '!'
!addr ins               Assemble instruction to address
!<space> ins            Assemble next instruction
!addrL                  Disassemble from address
!L                      Disassemble next page
!<cr>                   Return to wozmon
Believe it or not, the whole package fits in about 850 bytes.

Details in de 6502 forum, where all the work was done. Thanks a million to Mike T. Barry.
http://forum.6502.org/viewtopic.php?f=2&t=5884

BTW: we do have a working ROR instruction on this one, so v6502 isn't really authentic :-)

Re: v6502 mini-assembler in Apple-1 emulator

Posted: 08 Feb 2020, 14:37
by marcelk
The mini-assembler now has its entry point moved to $EEE because that's easier to remember than $D13. So from wozmon you enter its `!'-prompt with:

Code: Select all

EEER
The I/O (keyboard, display) is now handled by PIA chip emulation instead of the v6502 BRK instruction. In the original Apple-1, all I/O goes through the memory mapped PIA chip that's snooping on addresses $D010..$D013. The Gigatron emulation now mimics these addresses! The "software PIA" is implemented as a vertical blank interrupt that monitors these addresses an reacts to changes accordingly :D . The behaviour isn't 100.00% identical, because doing that requires putting hooks in the v6502 instructions themselves and that's not worth it. But now it comes pretty pretty close to how the real Apple-1 works. We need just two tweaks:

First, ECHO must avoid a race condition, so we rewrote it from

Code: Select all

FFEF 2C 12 D0    ECHO    BIT DSP
FFF2 30 FB               BMI ECHO
FFF4 8D 12 D0            STA DSP
FFF7 60                  RTS
into:

Code: Select all

FFEF 8D 12 D0    ECHO    STA DSP
FFF2 2C 12 D0    WAIT    BIT DSP
FFF5 30 FB               BMI WAIT
FFF7 60                  RTS
I'm sure Woz wouldn't mind, and it should work on original hardware as well (not tested :-)).

Second, reading KBD doesn't clear its bit 7. But sending out a character does clear this bit instead, and that fools practically all A1 programs.

EEER.png
EEER.png (43.69 KiB) Viewed 1228 times

P.S.1: Two things provisionally broke and still need to be fixed:
  • The `@'-cursor is missing because the vIRQ handler simply doesn't draw it (yet).
  • Integer BASIC (E000R) is momentarily broken, because lack of stack space. The PIA emulation and interrupt handler eat 8 bytes and that broke the camel's back. It takes a bit of effort to win back that space.
[Edit: Both issues have been fixed already.]

P.S.2: The above also means that this doesn't run on stock ROM v4 anymore. ROM v4 doesn't have the vertical blank interrupt. You have to build a dev.rom instead. (Or wait for ROM v5 to come out, but there's no schedule for that.)

Re: v6502 mini-assembler in Apple-1 emulator

Posted: 17 Feb 2020, 07:54
by marcelk
With recent commits the `@'-cursor has returned. This time its blinking rate and duty cycle are derived from the original schematics. In the Apple-1 a 555 timer does the blinking with R1=R2=10k and C=25uF. The vIRQ handler uses those characteristics, and I verified the result against a video I took last year. We can now say that next to the MCS6520 PIA and 6502 CPU we also emulate the 555 chip...

When software can do it, there's no need to have hardware for it.

Apple-1 555 timer.png
Apple-1 555 timer.png (41.48 KiB) Viewed 1135 times

Re: v6502 mini-assembler in Apple-1 emulator

Posted: 24 Mar 2020, 16:03
by marcelk
The mini-assembler's usage is now displayed when starting it with EEER. But you can skip this with an easy-to-remember alternative entry point.

When toying with 6502 code and making mistakes, the system appears more stable than I expected. This is because in v6502 practically all invalid instructions map to BRK. And unlike on the real Apple-1, BRK reenters the wozmon. However, stepping upon the zero-page variables under $40 is still an almost certain way to crash the system.

With this, A1 basic and the two puzzle games, I believe the Apple-1 emulation on the Gigatron is as good as it can get. Please feel free to play with this and report any unexpected behaviour. You need to build 'dev.rom' with 'make', and load it in an emulator or put in on an EPROM.

Usage.png
Usage.png (49.53 KiB) Viewed 211 times