126 lines
4.4 KiB
Plaintext
126 lines
4.4 KiB
Plaintext
!cpu 6502
|
|
!to "../build/A2FC.SYSTEM#FF2000",plain
|
|
*=$2000
|
|
;
|
|
; A2FC.SYSTEM
|
|
; (c) 2018 by 4am
|
|
; a very small DHGR graphics viewer
|
|
; takes pathname of .a2fc file (in $2006),
|
|
; loads it,
|
|
; displays it,
|
|
; waits for key,
|
|
; quits via MLI
|
|
;
|
|
|
|
;
|
|
; MLI commands
|
|
;
|
|
kMLIOpen = $C8
|
|
kMLIRead = $CA
|
|
kMLIClose = $CC
|
|
kMLIQuit = $65
|
|
;
|
|
; other stuff
|
|
;
|
|
aFileBuffer = $9200
|
|
MLI = $BF00
|
|
MACHID = $BF98
|
|
|
|
jmp Start ; magic jump
|
|
!byte $EE,$EE ; magic bytes
|
|
!byte $40 ; length of sStartupPath
|
|
sStartupPath
|
|
!fill $40
|
|
Start
|
|
ldy #(CodeEnd-CodeStart) ; copy code to lower memory so we can load graphic at $2000
|
|
- ldx CodeStart-1,y ; the last byte fetched (3, for the MLI_OPEN parameter count)
|
|
; is later re-used for unrelated purposes
|
|
stx $4f,y
|
|
dey
|
|
bne - ; Y is 0 on exit, required later
|
|
;CheckFor128K
|
|
lda MACHID
|
|
and #$30
|
|
cmp #$30 ; 128K?
|
|
beq + ; yes, continue
|
|
sty sStartupPath ; no, trash startup path so MLI_OPEN fails and we quit immediately
|
|
+ jsr MLI ; open file
|
|
!byte kMLIOpen
|
|
!word mliParamForOpen
|
|
inx ; convert to kMLIReadOrQuitCount, clear Z flag
|
|
stx <mliparam ; set parameter count for MLI call
|
|
; both Read and Quit accept four parameters
|
|
!cpu 65816
|
|
sep #2 ; set Z flag on 65816 only
|
|
!cpu 6502
|
|
bne + ; conditionally skip GS-specific code
|
|
lda $c029
|
|
and #$1f
|
|
sta $c029
|
|
+ jmp ReadFile
|
|
|
|
CodeStart
|
|
!pseudopc $50 {
|
|
mliParamForOpen
|
|
!byte 3 ; MLI_OPEN parameter count, but later re-used for unrelated purposes
|
|
!word sStartupPath
|
|
mliparam=*+1
|
|
!word aFileBuffer
|
|
mliParamForClose
|
|
!byte $00 ; ProDOS file refnum (filled by MLI_OPEN call)
|
|
; because the first file refnum will always be 1, this value is
|
|
; later re-used as the parameter count for the MLI_CLOSE call
|
|
!word $2000 ; data address
|
|
!byte $00
|
|
CopyToAux=*+1
|
|
CopyToAuxLow=*+1
|
|
CopyToAuxHigh=*+2
|
|
ReadFile
|
|
jsr Read ; JSR (#$20) is high part of data length
|
|
; Read is replaced by read length ($2000)
|
|
; and then used by main->aux copy loop
|
|
; read first half of graphic (belongs in auxmem)
|
|
; does not return if error
|
|
;DHGRCopy
|
|
sta $C005 ; read from mainmem, write to auxmem
|
|
- lda (CopyToAux),y ; Y is zero from first loop
|
|
sta (CopyToAux),y ; Y is zero from first loop
|
|
iny
|
|
bne -
|
|
inc <(CopyToAuxHigh)
|
|
bit <(CopyToAuxHigh) ; copy until $4000
|
|
bvc -
|
|
SoftswitchBase=*+1
|
|
sta $C000,x ; read from mainmem, write to mainmem ($C004 because X is 4 from above)
|
|
jsr Read ; read second half of graphic (stays in main memory)
|
|
; does not return if error
|
|
;DHGRShow
|
|
ldx #(softswitches_e-softswitches)-1
|
|
- ldy <softswitches,x ; the last byte fetched is 0 to hit $C000, this is re-used later
|
|
; for unrelated purposes
|
|
sta (SoftswitchBase),y ; enable DHGR graphics display by hitting all the right softswitches
|
|
; in the following order $C057,$C054,$C052,$C050,$C00D,$C05E,$C000
|
|
dex
|
|
bpl -
|
|
;WaitForKey
|
|
- lda (SoftswitchBase),y ; $C000 because Y is 0 from above
|
|
bpl -
|
|
Close
|
|
jsr MLI ; close all files
|
|
!byte kMLIClose
|
|
!word mliParamForClose
|
|
Quit
|
|
lsr <mlicmd ; MLI_QUIT ($65) is half of MLI_READ ($CA) so that's great
|
|
Read
|
|
jsr MLI
|
|
mlicmd !byte kMLIRead
|
|
!word mliparam
|
|
bcs Close ; error during open or read? close & quit
|
|
rts
|
|
|
|
softswitches ; array of low bytes for $c0xx accesses
|
|
!byte 0,$5e,$0d,$50,$52,$54,$57
|
|
softswitches_e
|
|
}
|
|
CodeEnd
|