8bitlenser/lenser/iigs/viewer/iigs.s
2026-07-03 19:35:35 -07:00

116 lines
3.2 KiB
ArmAsm

; lenser -- Apple IIGS Super Hi-Res boot loader + viewer (8-bit, no GS/OS).
;
; The Disk II boot ROM (slot 6) loads track 0 sector 0 to $0800 and JMPs $0801.
; This re-entrant loader reads the 32K SHR block (pixels $2000-$9CFF, SCBs
; $9D00, palettes $9E00) into main RAM $2000-$9FFF, then copies it to AUX RAM
; with SHR shadowing enabled -- so the writes mirror into bank $E1 (the SHR
; screen) -- and turns SHR on (NEWVIDEO bit 7). All 8-bit, no 65C816 needed.
* = $0800
.byte $01 ; ROM scratch (boot sector byte 0)
entry: ; $0801, re-entered after every ROM read
lda dpage
cmp #$a0
bcs done ; loaded $2000..$9FFF -> show it
lda psec
cmp #$10
bcc readit ; sectors left on this track
jsr seeknext ; finished a track -> step to the next
lda #$00
sta psec
readit:
lda psec
sta $3d ; desired sector
lda curtrk
sta $41 ; desired track
lda #$00
sta $26 ; buffer lo
lda dpage
sta $27 ; buffer hi
inc psec
inc dpage
ldx $2b ; slot*16 (set by boot ROM)
jmp $c65c ; slot 6 ROM read; reads sector then JMP $0801
done:
; Turn on Super Hi-Res (bit 7) AND linearize (bit 6) FIRST. With these
; set, CPU writes to bank $E1 $2000-$9FFF are de-interleaved by hardware
; into the megaII layout the video reads -- so we can copy our linear SHR
; block straight in and it displays correctly.
lda $c029
ora #$c0
sta $c029
; copy 32K from bank $00 $2000 -> bank $E1 $2000 (65C816 block move)
clc
xce ; -> native mode
rep #$30 ; 16-bit A/X/Y
.al
.xl
lda #$7fff ; count-1 (32768 bytes)
ldx #$2000 ; source offset
ldy #$2000 ; dest offset
.byte $54, $e1, $00 ; MVN src bank $00 -> dest bank $E1
sep #$30 ; 8-bit
.as
.xs
sec
xce ; -> emulation mode
lda $c034 ; border colour is the low nibble of $C034
and #$f0
sta $c034 ; black border
hang:
jmp hang
; advance the head one track (two half-steps), phase-overlap step.
seeknext:
inc curtrk
lda #$00
sta $0a
jsr onestep
jsr onestep
lda halftrk
and #$03
asl
ora $2b
tax
lda $c080,x
rts
onestep:
lda halftrk
clc
adc #$01
and #$03
asl
ora $2b
tax
lda $c081,x
ldx $0a
lda ontable,x
jsr wait
lda halftrk
and #$03
asl
ora $2b
tax
lda $c080,x
ldx $0a
lda offtable,x
jsr wait
inc halftrk
inc $0a
rts
ontable: .byte $13,$0a,$08,$06
offtable: .byte $46,$1a,$10,$0c
wait:
tay
w1: ldx #$00
w2: dex
bne w2
dey
bne w1
rts
psec: .byte $01
dpage: .byte $20
halftrk: .byte $00
curtrk: .byte $00