4cade/src/hw.accel.a

401 lines
11 KiB
Plaintext
Raw Normal View History

;license:MIT
2020-03-17 01:58:05 +00:00
;(c) 2019-2020 by 4am & qkumba
;
; Functions to enable and disable acceleration on various
; Apple II models, cards, and environments
;
; Forked from NORMFAST Release 6 (see changelog below)
;
; No functional changes to the acceleration routines, but for
; Total Replay, we split the machine identification code from
; the (de)acceleration code, because we can do the ID part once
; at program startup (when ROM is easily available), then
; (de)accelerate repeatedly from the language card (when ROM
; is switched out).
2018-08-27 19:39:08 +00:00
;
; --------------------------------------------------------------
;
; Original changelog and documentation:
;
;;; NORMFAST Disable/enable Apple II compatible accelerator
; (no copyright info given)
;
; Release 7 2019-11-27 FASTChip control just like ZipChip.
; Prevents unexpected acceleration by user.
;
2018-08-27 19:39:08 +00:00
; Release 6 2017-10-05 Fix Mac IIe card check
;
; Release 5 2017-09-27 Add Macintosh IIe Card. Addon
; accelerators are now set blindly, so will access
; annunciators/IIc locations and may trigger the
; paddle timer.
; No plans for the Saturn Systems Accelerator which would
; require a slot search.
;
; Release 4 2017-09-06 Add Laser 128EX, TransWarp I, UW
;
; Release 3 2017-08-29 Change FASTChip partially back to
; release 1, which seems to work the way release 2 was
; intended?!
;
; Release 2 2017-08-27 change enable entry point, add Zip
; Chip, change setting FASTChip speed to disable/enable
;
; Release 1 2017-08-25 IIGS, //c+ and FASTChip
;
; WARNING: The memory location to set the accelerator
; speed may overlap existing locations such as:
; annuciators or Apple //c specific hardware
; paddle trigger
;
; Known to work: IIGS, //c+
; Theoretically: FASTChip, Laser 128EX, Mac IIe Card,
; TransWarp I, trademarked German product, Zip Chip
;
; BRUN NORMFAST or CALL 768 to disable the accelerator.
; CALL 771 to enable the accelerator.
; Enabling an older accelerator may set maximum speed.
; Accelerators such as the FASTChip or Zip Chip can run
; slower than 1Mhz when enabled.
;
; NORMFAST is position independent and can be loaded most
; anywhere in the first 48K of memory.
; The ROMs must be enabled to identify the model of the
; computer.
;
; This was originally for the //c+ which is normally
; difficult to set to 1Mhz speed.
; The other expected use is to set the speed in a program.
;
; Written for Andrew Jacobs' Java based dev65 assembler at
; http://sourceforge.net/projects/dev65 but has portability
; in mind.
; addresses are lowercase, constant values are in CAPS
romid = $FBB3
; $38=][, $EA=][+, $06=//e compatible
ROMID_IIECOMPAT = 6
romid_ec = $FBC0
; $EA=//e original, $E0=//e enhanced, $E1=//e EDM, $00=//c
; Laser 128s are $E0
romid_c = $FBBF
; $FF=original, $00=Unidisk 3.5 ... $05=//c+
ROMID_CPLUS = 5
romid_maciie_2 = $FBDD ; 2
; IIGS
idroutine = $FE1F ; SEC, JSR $FE1F, BCS notgs
gsspeed = $C036
GS_FAST = $80 ; mask
; //c+ Cache Glue Gate Array (accelerator)
cgga = $C7C7 ; entry point
CGGA_ENABLE = 1 ; fast
CGGA_DISABLE = 2 ; normal
CGGA_LOCK = 3
CGGA_UNLOCK = 4 ; required to make a change
; Macintosh IIe Card
maciie = $C02B
MACIIE_FAST = 4 ; mask
l128irqpage = $C4
; From the 4.2, 4.5 and EX2 ROM dumps at the Apple II
; Documentation Project, the Laser 128 IRQ handlers are
; in the $C4 page.
; A comp.sys.apple2 post says the 6.0 ROM for the 128 and
; 128EX are identical, so there may not be an easy way to
; tell a plain 128 from an (accelerated) 128EX.
irq = $FFFE ; 6502 IRQ vector
; may overlap with paddle trigger
ex_cfg = $C074 ; bits 7 & 6 for speed
EX_NOTSPEED = $3F
EX_1MHZMASK = $0
EX_2MHZMASK = $80 ; 2.3Mhz
EX_3MHZMASK = $C0 ; 3.6Mhz
; FASTChip
fc_lock = $C06A
fc_enable = $C06B
2019-11-27 06:17:22 +00:00
fc_config = $C06E
fc_data = $C06F
2019-12-29 22:42:48 +00:00
FC_UNLOCK = $6A ; write 4 times
FC_LOCK = $A6
2018-08-27 19:39:08 +00:00
FC_1MHZ = 9
FC_ON = 40 ; doco says 16.6Mhz
2019-12-29 22:42:48 +00:00
FC_SPKR = 2
FC_HIFI = 4
2018-08-27 19:39:08 +00:00
; TransWarp I
; may overlap with paddle trigger
tw1_speed = $C074
TW1_1MHZ = 1
TW1_MAX = 0
; Trademarked German accelerator
; overlaps annunciator 2 & //c mouse interrupts
uw_fast = $C05C
uw_1mhz = $C05D
; Zip Chip
; overlaps annunciator 1 & //c vertical blank
zc_lock = $C05A
ZC_UNLOCK = $5A ; write 4 times
ZC_LOCK = $A5
zc_enable = $C05B
iobase = $C000 ; easily confused with kbd
BuildAcceleratorFunction
; in: none
; out: A/Y points to lo/hi address of code block
; X contains length of code block
2018-08-27 19:39:08 +00:00
;; first check built-in accelerators
ldx romid
cpx #ROMID_IIECOMPAT
bne build_addon ; not a //e
2018-08-27 19:39:08 +00:00
ldx romid_ec
beq iic ; //c family
2018-08-27 19:39:08 +00:00
; not worth the bytes for enhanced //e check
ldx irq+1
cpx #l128irqpage
bne gscheck
2018-08-27 19:39:08 +00:00
; a Laser 128, hopefully harmless on a non EX
ldy #EX_3MHZMASK ; phew, all needed bits set
ldx #<(ex_cfg)
2019-10-09 17:22:55 +00:00
bne build_setspeed ; always branches
2018-08-27 19:39:08 +00:00
gscheck
pha
sec
jsr idroutine
pla
bcs maccheck ; not a gs
2018-08-27 19:39:08 +00:00
; set IIGS speed
ldy #GS_FAST
ldx #<(gsspeed)
bne build_setspeed ; always branches
2018-08-27 19:39:08 +00:00
maccheck
ldx romid_maciie_2
cpx #2
bne build_addon ; no built-in accelerator
2018-08-27 19:39:08 +00:00
; the IIe Card in a Mac
ldy #MACIIE_FAST
ldx #<(maciie)
bne build_setspeed ; always branches
2018-08-27 19:39:08 +00:00
iic
ldx romid_c
cpx #ROMID_CPLUS
2019-12-10 01:38:52 +00:00
bne build_addon ; not a //c+, eventually hit Zip
lda #<iicplus
ldy #>iicplus
ldx #(end_iicplus-iicplus)
rts
build_setspeed
stx setspeed_x
sty setspeed_y
lda #<setspeed
ldy #>setspeed
ldx #(end_setspeed-setspeed)
rts
build_addon
2019-12-29 22:42:48 +00:00
lda #FC_UNLOCK ; change Fastchip speaker setting to 'HIFI'
sta fc_lock ; (improves sound on most games)
sta fc_lock ; (setting reverts on power cycle)
sta fc_lock
sta fc_lock
sta fc_enable
lda #FC_SPKR
sta fc_config
lda #FC_HIFI
sta fc_data
lda #FC_LOCK
sta fc_lock
lda #<addon
ldy #>addon
ldx #(end_addon-addon)
rts
;-----------------------------------------------------------
; 3 distinct accelerator functions
;
; Only 1 of these will be required on any particular machine.
;
; Each has 2 entry points, +0 to disable acceleration and
; +3 to enable acceleration.
;
; setspeed must be self-modified before use (setspeed_x and
; setspeed_y).
;
;-----------------------------------------------------------
2018-08-27 19:39:08 +00:00
; Function #1: Apple IIc+
2019-11-13 02:57:35 +00:00
iicplus !pseudopc DisableAccelerator {
2018-08-27 19:39:08 +00:00
; Set //c+ speed. Uses the horrible firmware in case other
; code works "by the book", that is can check and set
; whether the accelerator is enabled.
; The //c+ is otherwise Zip compatible.
2019-11-13 02:57:35 +00:00
; This code cannot run from LC, and *must* bank in ROM.
; CGGA assumes that ROM is already banked in.
2019-12-05 05:11:58 +00:00
lda #$3A ; DEC, disable accelerator entry point
2019-11-13 02:57:35 +00:00
!byte $2C ; BIT <ABSOLUTE>, hide next lda #
2019-12-05 05:11:58 +00:00
lda #$4A ; LSR, enable accelerator entry point
sta @pokery ; action after CGGA_UNLOCK
2018-08-27 19:39:08 +00:00
; cgga calls save X and Y regs but sets $0 to 0
; (this will get a laugh from C programmers)
2019-11-27 21:51:43 +00:00
lda $0
pha
php
sei ; timing sensitive
2019-12-05 05:11:58 +00:00
jsr @jiggerypokery
2020-03-14 02:33:41 +00:00
lda gMachineInDHGRMode
bne + ; DHGR mode doesn't need fix
sta $C05B ; fix HGR-mode colouring
+ plp ; restore interrupt state
2019-11-13 02:57:35 +00:00
pla
sta $0
rts
2018-08-27 19:39:08 +00:00
2019-12-05 05:11:58 +00:00
@jiggerypokery
tsx
ldy #(@endpokery - @jiggery)
@copyiicp
lda @jiggery-1,y
pha
dey
bne @copyiicp
txa
tsx
iny
!cpu 65c02
phy
phx
!cpu 6502
tax
rts
2019-11-13 02:57:35 +00:00
@jiggery
+READ_ROM_NO_WRITE
2019-12-05 05:11:58 +00:00
lda #CGGA_LOCK ; should lock after a change
pha
2019-11-13 02:57:35 +00:00
@pokery
2019-12-05 05:11:58 +00:00
nop ; SMC
2019-11-13 02:57:35 +00:00
pha
2019-12-05 05:11:58 +00:00
lda #CGGA_UNLOCK ; unlock to change
pha
2019-12-05 05:11:58 +00:00
jsr cgga ; disable/enable
jsr cgga
2019-11-13 02:57:35 +00:00
jsr cgga ; reads parm from stack, must JSR
2019-12-05 05:11:58 +00:00
txs
2019-11-07 05:20:12 +00:00
+READ_RAM2_WRITE_RAM2
rts
2019-11-13 02:57:35 +00:00
@endpokery
}
end_iicplus
2018-08-27 19:39:08 +00:00
; Function #2: IIgs, Laser 128EX, or IIe card
;; setspeed - set 1Mhz with AND and fast with OR
2018-08-27 19:39:08 +00:00
;
; A = lsb set for normal speed
; X = low byte address of speed location
; Y = OR mask for fast
setspeed
lda #1 ; disable accelerator entry point
!byte $2C ; BIT <ABSOLUTE>, hide next lda #
lda #0 ; enable accelerator entry point
setspeed_x=*+1
ldx #$FD ; SMC
setspeed_y=*+1
ldy #$FD ; SMC
lsr
tya
bcs setnorm
ora iobase,x
2020-02-05 17:19:26 +00:00
ldy #$d6
bne setsta ; always branches
setnorm
eor #$FF
and iobase,x
2020-02-05 16:20:54 +00:00
ldy #$56
setsta
sta iobase,x
2020-02-05 16:20:54 +00:00
sty $7FE ; Laser checks it
rts
end_setspeed
2018-08-27 19:39:08 +00:00
; Function #3: Card-based accelerator (TransWarp, ZipChip,
; FastChip, &c.)
; We blindly set switches for all known cards.
2018-08-27 19:39:08 +00:00
addon
lda #1 ; disable accelerator entry point
!byte $2C ; BIT <ABSOLUTE>, hide next lda #
lda #0 ; enable accelerator entry point
2018-08-27 19:39:08 +00:00
; TransWarp I
sta tw1_speed
2018-08-27 19:39:08 +00:00
2019-11-27 06:17:22 +00:00
; trademarked accelerator from Germany
2018-08-27 19:39:08 +00:00
tay
sta uw_fast,y ; value does not matter, SMC
; no blind setting on the IIc
; it has unwanted side-effects
2019-11-27 06:17:22 +00:00
; Zip Chip
2019-11-27 06:17:22 +00:00
ldy #FC_1MHZ
eor #1
tax
2019-11-27 06:17:22 +00:00
beq +
ldy #FC_ON
+ lda #ZC_UNLOCK
php
sei ; timing sensitive
2019-12-10 01:38:52 +00:00
sta zc_lock
sta zc_lock
sta zc_lock
sta zc_lock
lsr ; not ZC_LOCK or ZC_UNLOCK
sta zc_lock,x ; disable/enable
lda #ZC_LOCK
sta zc_lock
2019-12-10 05:13:10 +00:00
sta $C05D ; fix colouring
2018-08-27 19:39:08 +00:00
2019-11-27 06:17:22 +00:00
FASTChip
lda #FC_UNLOCK
sta fc_lock
sta fc_lock
sta fc_lock
sta fc_lock
sta fc_enable
2019-11-27 06:17:22 +00:00
lda #0
sta fc_config
sty fc_data
lda #FC_LOCK
sta fc_lock
2019-11-27 06:17:22 +00:00
plp ; restore interrupt state
rts
2019-11-27 21:51:43 +00:00
end_addon